C# 启动AppService失败:无法加载文件或程序集';X';。进程无法访问该文件,因为其他进程正在使用该文件
我们使用Azure DevOps发布管道将WebApi(ASP.NET Core 3.1)部署到Azure AppService。管道中的步骤如下(我们尝试确保应用程序在部署之前完全停止):C# 启动AppService失败:无法加载文件或程序集';X';。进程无法访问该文件,因为其他进程正在使用该文件,c#,asp.net-core,azure-appservice,C#,Asp.net Core,Azure Appservice,我们使用Azure DevOps发布管道将WebApi(ASP.NET Core 3.1)部署到Azure AppService。管道中的步骤如下(我们尝试确保应用程序在部署之前完全停止): 禁用Web作业(通过将设置变量WebJobs\u STOPPED和WebJobs\u Disable\u SCHEDULE设置为1) 停止应用服务(任务Azure应用服务管理-停止应用服务) Azure应用程序服务部署(选项:Web部署、使应用程序脱机、重命名锁定的文件) 为EF迁移应用SQL脚本(如果有
- 禁用Web作业(通过将设置变量
和WebJobs\u STOPPED
设置为WebJobs\u Disable\u SCHEDULE
)1
- 停止应用服务(任务Azure应用服务管理-停止应用服务)
- Azure应用程序服务部署(选项:Web部署、使应用程序脱机、重命名锁定的文件)
- 为EF迁移应用SQL脚本(如果有)
- 启动应用程序服务
- 启用WebJobs
[2020-09-03 19:36:20Z FTL] Host terminated unexpectedly <s:>
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=5.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The process cannot access the file because it is being used by another process. (0x80070020)
Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=5.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The process cannot access the file because it is being used by another process. (0x80070020)
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at AutoMapper.ServiceCollectionExtensions.<>c.<AddAutoMapperClasses>b__14_2(Assembly a)
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at AutoMapper.ServiceCollectionExtensions.AddAutoMapperClasses(IServiceCollection services, Action`2 configAction, IEnumerable`1 assembliesToScan)
at AutoMapper.ServiceCollectionExtensions.AddAutoMapper(IServiceCollection services, Action`2 configAction, Assembly[] assemblies)
at AutoMapper.ServiceCollectionExtensions.AddAutoMapper(IServiceCollection services)
at Dac6.WebApi.Startup.ConfigureServices(IServiceCollection services) in F:\agent2\_work\19\s\server\Dac6.WebApi\Startup.cs:line 82
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.MethodInfoExtensions.InvokeWithoutWrappingExceptions(MethodInfo methodInfo, Object obj, Object[] parameters)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass15_0.<BuildStartupServicesFilterPipeline>g__RunPipeline|0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass14_0.<ConfigureServices>g__ConfigureServicesWithContainerConfiguration|0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.WebHost.Initialize()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at Dac6.WebApi.Program.Main(String[] args) in F:\agent2\_work\19\s\server\Dac6.WebApi\Program.cs:line 27
[2020-09-03 19:36:20Z FTL]主机意外终止
System.Reflection.ReflectionTypeLoadException:无法加载一个或多个请求的类型。
无法加载文件或程序集“Microsoft.IdentityModel.Tokens,版本=5.5.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”。进程无法访问该文件,因为其他进程正在使用该文件。(0x80070020)
无法加载文件或程序集“Microsoft.IdentityModel.Tokens,版本=5.5.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”。进程无法访问该文件,因为其他进程正在使用该文件。(0x80070020)
位于System.Reflection.RuntimeModule.GetTypes(RuntimeModule)
在System.Reflection.RuntimeAssembly.get_DefinedTypes()中
位于AutoMapper.ServiceCollectionExtensions.c.b_u14_u2(组件a)
在System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToArray()中
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1源)
在AutoMapper.ServiceCollectionExtensions.AddAutoMapperClasses(IServiceCollection服务,Action`2 configAction,IEnumerable`1 assembliesToScan)
在AutoMapper.ServiceCollectionExtensions.AddAutoMapper(IServiceCollection服务,操作'2 configAction,程序集[]程序集)
在AutoMapper.ServiceCollectionExtensions.AddAutoMapper(IServiceCollection服务)
在F:\agent2\\u work\19\s\server\Dac6.WebApi\Startup.cs中的Dac6.WebApi.Startup.ConfigureServices(IServiceCollection服务)处:第82行
在System.RuntimeMethodHandle.InvokeMethod(对象目标、对象[]参数、签名符号、布尔构造函数、布尔WrapeExceptions)
在System.Reflection.RuntimeMethodInfo.Invoke(对象obj、BindingFlags invokeAttr、绑定器绑定器、对象[]参数、CultureInfo区域性)
位于Microsoft.AspNetCore.Hosting.MethodInfoExtensions.InvokeWithoutWrappingExceptions(MethodInfo MethodInfo、Object obj、Object[]参数)
位于Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(对象实例,IServiceCollection服务)
在Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.c_uuDisplayClass9_0.g_uStartup | 0(IServiceCollection serviceCollection)
在Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder'1.c_uDisplayClass15_0.g_uRunPipeline | 0(iSeries收集服务)
位于Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(对象实例,IServiceCollection服务)
在Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.c__DisplayClass8_0.b__0(iSeries收集服务)上
在Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.c_uuDisplayClass14_0.g_u配置服务WithContainerConfiguration | 0(iSeries收集服务)
位于Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(iSeries收集服务)
在Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices()上
在Microsoft.AspNetCore.Hosting.WebHost.Initialize()中
在Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()上
在F:\agent2\\u work\19\s\server\Dac6.WebApi\Program.cs中的Dac6.WebApi.Program.Main(字符串[]args)处:第27行
我们遇到了相同的问题。我们的应用服务计划中有六个实例,当错误发生时,并不一定会发生在所有实例上。“你找到解决办法了吗?”@MikeSchenk没有。我猜这与WebJobs有关。在最新版本的应用程序中,我们已经迁移到Azure功能(在AppService计划中),从那时起我就没有遇到过这种问题。也许禁用WebJobs并不能阻止它们或不能完全阻止它们。我们也遇到了同样的问题。我们的应用服务计划中有六个实例,当错误发生时,并不一定会发生在所有实例上。“你找到解决办法了吗?”@MikeSchenk没有。我猜这与WebJobs有关。在最新版本的应用程序中,我们已经迁移到Azure功能(在AppService计划中),从那时起我就没有遇到过这种问题。也许禁用WebJobs并不能阻止它们,或者不能完全阻止它们。。