已发布的 MVC3 应用程序结果: "Could not load file or assembly 'System.Web.Mvc'"



我正在尝试将一个新的MVC3项目部署到Azure网站。

步骤:

  1. 使用Razor View Engine在VS 2012中创建一个新的MVC3互联网应用程序。添加到web.config文件
  2. F5进行本地构建和调试,验证站点是否在本地调试中加载
  3. 创建一个新的azure网站并下载该网站的发布设置文件
  4. 使用步骤3中下载的发布设置发布网站

EXPECT>>发布时预期的站点负载。

ACTUAL>>"无法加载文件或程序集"System.Web.Mvc,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856a364e35"或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。">(下面是完整堆栈跟踪)

我知道这个示例项目曾经为我开箱即用地发布,没有任何错误,但我已经一年左右没有尝试过了

我在Stackoverflow上看到了一些类似的错误,但答案要么不相关,要么不完整:

  • 无法加载文件或程序集';系统网状物Mvc';-似乎不适用于发布到azure场景
  • 无法加载文件或程序集系统。网状物Http。发布到Azure网站后的WebHost-系统的CopyLocal已设置为"True"。网状物Mvc

我已经为此穷追不舍很长时间了。有人有什么建议吗?

Server Error in '/' Application.
--------------------------------------------------------------------------------

Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 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 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 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 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLMSoftwareMicrosoftFusion!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 [HKLMSoftwareMicrosoftFusion!EnableLog].

Stack Trace: 

[FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
Microsoft.Web.Mvc.ViewEngineFix.PreAppStart() +0
[InvalidOperationException: The pre-application start initialization method PreAppStart on type Microsoft.Web.Mvc.ViewEngineFix threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 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) +550
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
System.Web.Compilation.BuildManager.ExecutePreAppStart() +140
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
[HttpException (0x80004005): The pre-application start initialization method PreAppStart on type Microsoft.Web.Mvc.ViewEngineFix threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 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) +9877836
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext 

在您的问题中,您声明您的目标是MVC3,但Azure计算机似乎找不到该程序集的正确版本。它正在查找MVC二进制文件。这让我相信MVC3没有安装在您试图发布到的服务器上。

有几个选项可供选择:

  1. 将您的项目升级到MVC4并发布升级后的版本
  2. web.config中应用一组BindingRedirects,以便在运行时将MVC3重定向到MVC4

这是我认为您需要的一组绑定重定向,可能还有其他重定向,但每个重定向都会出现类似的错误:

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

相关内容

最新更新