【问题标题】:Could not load file or assembly - After stopping then starting Azure app service无法加载文件或程序集 - 停止后启动 Azure 应用服务
【发布时间】:2019-02-13 18:43:35
【问题描述】:

我正在将 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。

【问题讨论】:

  • 也许你可以试试这个答案。stackoverflow.com/a/4188166/10383250
  • 我在发布我的问题后不久就找到了解决方案,我将发布答案。它与您发布的链接相似。

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


【解决方案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 的评论会有所帮助,但我在他发布之前找到了解决方案。

【讨论】:

    猜你喜欢
    • 2016-03-29
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多