无法加载文件或程序集-停止后再启动Azure应用服务

时间:2019-02-13 18:43:36

标签: c# asp.net asp.net-mvc razor azure-web-sites

我正在将ASP.NET MVC Web应用程序发布到Azure应用程序服务。最初发布时运行find。如果我关闭了应用程序服务,然后在几个小时后再次启动它,当我尝试在浏览器中打开网站时收到此错误,直到应用程序关闭然后再次打开后,我才能弄清它为什么起作用:

Server Error in '/' Application.
Could not load file or assembly 'RazorEngine, Version=3.4.1.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'RazorEngine, Version=3.4.1.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'RazorEngine, Version=3.4.1.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


Stack Trace:


[FileLoadException: Could not load file or assembly 'RazorEngine, Version=3.4.1.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]

[FileLoadException: Could not load file or assembly 'RazorEngine, Version=3.7.2.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
    System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +36
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.Assembly.Load(AssemblyName assemblyRef) +36
   MyProject.Core.Plugins.PluginManager.PerformFileDeploy(FileInfo plug) +460
   MyProject.Core.Plugins.PluginManager.Initialize() +3201

 [Exception: Could not load file or assembly 'RazorEngine, Version=3.7.2.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
    Could not load file or assembly 'RazorEngine, Version=3.4.1.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   MyProject.Core.Plugins.PluginManager.Initialize() +4423

[InvalidOperationException: The pre-application start initialization method Initialize on type MyProject.Core.Plugins.PluginManager threw an exception with the following error message:     Could not load file or assembly 'RazorEngine, Version=3.7.2.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Could not load file or assembly 'RazorEngine, Version=3.4.1.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
.]

System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +615         System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +549


[HttpException (0x80004005): The pre-application start initialization method Initialize on type MyProject.Core.Plugins.PluginManager threw an exception with the following error message: Could not load file or assembly 'RazorEngine, Version=3.7.2.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Could not load file or assembly 'RazorEngine, Version=3.4.1.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10075124
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET     Version:4.7.3282.0  

我认为这与MyProject.Core.Plugins.PluginManager程序集有关。这是我的解决方案中的一个项目,该项目由Web应用程序使用。有时,当我在本地调试并更改到剃须刀页面时,会收到与此相关的错误。它不是很具体,也不会持续发生。我可以通过清理解决方案并重新构建来解决本地开发环境中的问题。我在本文中发布的错误与每次我关闭然后再打开应用程序服务时一致。

This帖子讨论了特定的错误,但这是一篇过时的文章,并谈到了我在Azure或开发环境中未使用的GAC。

1 个答案:

答案 0 :(得分:1)

我必须将插件项目packages.json中的RazorEngine版本更改为Web项目所使用的相同版本。

<package id="RazorEngine" version="3.4.1" targetFramework="net45" />

<package id="RazorEngine" version="3.7.2" targetFramework="net45" />

然后我跑了Update-Package -Reinstall RazorEngine

This帖子使我朝着正确的方向前进。 GeorgeChen的评论会有所帮助,但我在他发布之前找到了解决方案。