Starting AppService fails with: Could not load file or assembly 'X'. The process cannot access the file because it is being used by another process

1

We deploy WebApi (ASP.NET Core 3.1) to our Azure AppService using Azure DevOps release pipeline. The steps in the pipeline are as follows (we try to make sure the app is completely stopped before the deployment):

  • Disable WebJobs (by setting settings variables WEBJOBS_STOPPED and WEBJOBS_DISABLE_SCHEDULE to 1)
  • Stop AppService (Task Azure App Service manage - Stop App Service)
  • Azure App Service Deploy (Options: Web Deploy, Take App Offline, Rename locked files)
  • Apply SQL script for EF Migrations (if any)
  • Start AppService
  • Enable WebJobs

Then - sometimes - when we try to access the API we are getting error. Checking the error log on AppService, there is error about some DLL cannot be loaded because it is being used by another process, an example is shown below.

This happen sometimes and the locked assembly is usually different each time.

I wonder what other process could use assemblies from our application? Is there any antivirus running at AppService? How could we troubleshoot this further to find out the cause of the problem?

[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
c#
asp.net-core
azure-appservice
asked on Stack Overflow Sep 4, 2020 by eXavier

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0