本地-我的MVC4,asp.net,c#应用程序在IIS 8/Windows 8上运行良好.

在部署到Windows Server 2008时,我收到以下错误:

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

如果我从project properties/package/publish web中的"要部署的项目"下拉列表中 Select "仅运行此应用程序所需的文件",就会发生这种情况.

如果我 Select "此项目中的所有文件",它工作正常.

我猜Elmah依赖于旧版本的MVC或其他东西——我如何在不上传所有文件的情况下解决这个问题?

解决这样的问题最好的方法是什么?

谢谢

推荐答案

我在使用MVC4和Ninject时遇到了完全相同的问题.净4.5

为了解决这个问题,我必须向我的网站添加一个绑定重定向.配置文件:

  <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而不是旧版本.

Asp.net相关问答推荐

强制从 /bin 而不是 GAC 加载程序集?

使用进程外会话状态的 ASP.NET 应用程序中的 SQL Server 连接问题

捕获对 ASP.NET ASMX Web 服务的 SOAP 请求

未知的网络方法.参数名称:methodName

System.Net.Http 版本冲突导致构建警告

如何使用 javascript 获取 MVC 应用程序的基本 URL

ASP.NET - AppDomain.CurrentDomain.GetAssemblies() - AppDomain 重新启动后缺少程序集

在 ASP.NET 中更改错误消息的语言

判断会话是否为空

__doPostBack 未定义

你如何确定哪个验证器失败了?

ASP.NET RadioButton 与名称(组名)混淆

在 ASP.NET 中实现 404 的最佳方法

Azure Functions 中的 DI

SQLServer 与 StateServer 的 ASP.NET 会话状态性能

如何验证 WebClient 请求?

为什么混合 Razor Pages 和 VueJs 是一件坏事?

如何使用restsharp下载文件

从物理路径获取相对虚拟路径

x-powered by是什么意思?