微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/aspnet/254256.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐