2013-05-28 80 views
28

本地 - 我的MVC 4,asp.net,C#应用程序运行正常在IIS 8/Windows 8的无法加载文件或程序集“System.Web.Mvc,版本= 3.0.0.0,Elmah.MVC问题

当部署到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或什么东西 - 我如何解决这个问题,而不必上传所有的文件?

问题的最佳解决方式是什么来解决这样的情况?

谢谢。

回答

58

我不得不使用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

System.Web.Mvc的assemblyBinding配置为我工作! – EdmundYeung99

+2

也为我工作:-) – Baconbeastnz

+1

作品像ninject错误的魅力,谢谢! –

0

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

对于仅适用于ASP.NET WebAPI的应用程序,我会推荐Emah.Contrib.WebAPI包。这个软件包也可以通过NuGet安装。

0

在错误页面我有这样的:

LOG:应用程序配置文件中检测到重定向: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

下载的代码

希望这有助于

0

添加以下代码在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> 

相关问题