FileLoadException: Could not load file or assembly in WebRole (recycling instance)

雨燕双飞 提交于 2019-12-01 12:53:15

问题


My WebRole won't start but keeps restarting and throws this exception:

Application: WaIISHost.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: 
 System.IO.FileLoadException: Could not load file or assembly 'Autofac, Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Autofac, Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da'
   at MyDomain.Web.AutofacWebModule.Load(ContainerBuilder builder)
   at Autofac.Module.Configure(IComponentRegistry componentRegistry)
   at Autofac.ContainerBuilder.Build(IComponentRegistry componentRegistry, Boolean excludeDefaultModules)
   at Autofac.ContainerBuilder.Build(ContainerBuildOptions options)
   at MyDomain.Web.Startup.BuildAutofacContainer() in MyDomain.Web\Startup.cs:line 82
   at MyDomain.Web.WebRole.Run() in MyDomain.Web\WebRole.cs:line 25
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRoleInternal()
   at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.<StartRole>b__2()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

UPDATE. Added a full error description with the help of this article: Troubleshooting Scenario 7 – Role Recycling

UPDATE 2. Found a good article about the exception. Cloud Services roles recycling with the error “System.IO.FileLoadException: Could not load file or assembly”. It seems to be enough to fix the problem.

The reason it breaks is on my Azure instance, in E:\approot\bin\ there is no MyDomain.Web.config files with the redirections required by Autofac. And the web.config in E:\approot\ is not read by the WaIISHost.exe. And so it breaks.


回答1:


It needed the <role name>.dll.config file added to solution (same level as the web.config or app.config) (the Copy to Output Directory property to “Copy Always”). Then redeploying to Azure. This file should contain the bindingRedirect settings.



来源:https://stackoverflow.com/questions/35956076/fileloadexception-could-not-load-file-or-assembly-in-webrole-recycling-instanc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!