本文介绍了无法加载文件或程序'System.Web.Mvc,版本= 3.0.0.0,Elmah.MVC问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本地 - 我的MVC 4,asp.net,C#应用程序运行正常在IIS 8 / Windows 8的

Locally - my MVC 4, asp.net, c# app runs fine on IIS 8 / Windows 8.

当部署到Windows Server 2008,我得到这个错误:

When deployed to Windows Server 2008, I get this error:

Could not load file or assembly 'System.Web.Mvc, Version=3.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)

[FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=3.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)]
   Elmah.Mvc.Bootstrap.Initialize() +0

[InvalidOperationException: The pre-application start initialization method Initialize on type Elmah.Mvc.Bootstrap threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=3.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) +12881963
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +12881672
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +240
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): The pre-application start initialization method Initialize on type Elmah.Mvc.Bootstrap threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=3.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) +12881108
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722297

这会发生,如果我选择从项目部署的项目属性下拉'只运行该应用程序所需的文件/包/发布Web。

This happens if I select 'Only files needed to run this application' from the 'Items to deploy' drop down in project properties/package/publish web.

如果我选择在这个项目中的所有文件的正常工作。

If I select 'all files in this project' it works fine.

我想ELMAH是旧版本的MVC什么的依赖 - 我该如何解决这一问题,而无需上传的所有文件

I guess Elmah is reliant on an older version of MVC or something - how can I fix this without having to upload all the files?

请告诉我问题的最好办法解决的情况也是这样吗?

Whats the best way to problem solve situations like this?

感谢。

推荐答案

我不得不使用MVC4与Ninject专为.NET 4.5此相同的问题。

I had this exact same issue using MVC4 with Ninject built for .Net 4.5

要解决这个问题,我不得不添加绑定重定向到我的Web.config文件:
(在文件的结尾,就在< /结构> 标记)

To fix this i had to add a binding redirect to my Web.config file:(at the end of the file, just before the </configuration> tag)

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

这迫使Web服务器使用 System.Web.Mvc 4.0.0.0 代替旧版本。

This forces the web server to use System.Web.Mvc 4.0.0.0 instead of an older version.

这篇关于无法加载文件或程序'System.Web.Mvc,版本= 3.0.0.0,Elmah.MVC问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 14:33