asp.net – 无法加载文件或程序集“System.Web.Mvc,Version = 3.0.0.0,Elmah.MVC问题

本地 – 我的MVC 4,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,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,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,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中的“要部署的项目”下拉列表中选择“只需要运行此应用程序的文件”,就会发生这种情况。

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

我猜Elmah是依赖于一个旧版本的MVC或东西 – 我该如何解决这个问题,而不必上传所有的文件

什么是解决这种情况的最佳方式?

谢谢。

解决方法

我有这个完全相同的问题使用MVC4与Ninject为.Net 4.5

解决这个问题,我不得不添加一个绑定重定向到我的Web.config文件
(在文件末尾,紧靠< / configuration>标记之前)

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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....