无法加载文件或程序集&System; Web.Mvc,Version = 3.0.0.0,Elmah.MVC问题

时间:2013-05-28 16:28:27

标签: asp.net asp.net-mvc asp.net-mvc-4 assemblies elmah.mvc

本地 - 我的MVC 4,asp.net,c#app在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

如果我从项目属性/包/发布网络中的“要部署的项目”下拉列表中选择“仅运行此应用程序所需的文件”,则会发生这种情况。

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

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

解决问题的最佳方法是什么?

感谢。

7 个答案:

答案 0 :(得分:60)

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

答案 1 :(得分:0)

  

有一些程序用于解决问题,如果web.config中的绑定重定向无法解决问题,您可以尝试以下步骤进行修复:

1)在Visual Studio Solution Explorer树中,右键单击Web项目下的“引用”,然后选择“管理NuGet包”。

2)转到“浏览”标签,然后选择nuget.org作为包源。

3)搜索并安装以下软件包:NinjectNinject.Web.CommonNinject.MVC5

最好在Manage NuGet Packages的Updates选项卡上更新软件包,特别是Microsoft ASP.NET MVC

希望这会有所帮助......

答案 2 :(得分:0)

<dependentAssembly>
            ***<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-5.2.7.0"*** newVersion="5.2.7.0" />
        </dependentAssembly>

检查版本是否正确

答案 3 :(得分:0)

要安装System.Web.Mvc 3.0.0.0

1)安装windows web platform installer
2)从开始菜单打开Windows Web平台安装程序
3)转到Products标签
4)搜索MVC
5)安装MVC 3

enter image description here

答案 4 :(得分:-1)

您确定使用的是ASP.NET MVC(视图控制器等)吗?或者是您的Web应用程序是否仅使用ASP.NET WebAPI?如果是这样,那么你应该只安装ElMAH NuGet包和 Elmah.MVC。

对于仅限ASP.NET WebAPI的应用,我建议使用Emah.Contrib.WebAPI包。该软件包也可以通过NuGet安装。

答案 5 :(得分:-1)

在错误页面中我有这个:

日志:在应用程序配置文件中检测到重定向:5.1.0.0被重定向到5.2.3.0。

所以我必须将web.config中的这一行更改为 5.1.0.0 版本并且它有效!

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.1.0.0" />
    <!--<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> Older line -->
  </dependentAssembly>

我认为这是因为我从TFS下载代码时的版本问题

希望这有帮助

答案 6 :(得分:-2)

在web.config中添加以下代码:

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