无法启动AppService并显示以下信息:无法加载文件或程序集“ X”该进程无法访问该文件,因为该文件正在被另一个进程使用

问题描述

我们使用Azure DevOps发布管道将WebApi(ASP.NET Core 3.1)部署到Azure AppService。管道中的步骤如下(我们尝试确保应用在部署之前已完全停止):

  • 禁用WebJob(通过将设置变量WEBJOBS_STOPPEDWEBJOBS_disABLE_SCHEDULE设置为1
  • 停止AppService(任务Azure应用服务管理-停止应用服务)
  • Azure App Service部署(选项:Web部署,使App脱机,重命名锁定的文件
  • sql脚本应用于EF迁移(如果有)
  • 启动AppService
  • 启用WebJobs

然后-有时-当我们尝试访问API时,出现错误。检查AppService上的错误日志,由于某些进程正在使用另一个DLL,导致无法加载某些DLL的错误,如下所示。

有时会发生这种情况,并且锁定的组件通常每次都不同。

我想知道还有哪些其他进程可以使用我们应用程序中的程序集? AppService是否运行任何防病毒软件?我们如何进一步排除故障以找出问题的原因?

[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,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,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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)