Asp.net
無法載入文件或程序集 ‘System.Web.Mvc,版本 = 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, 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如果我從項目屬性/包/發布 web.xml 中的“要部署的項目”下拉列表中選擇“僅執行此應用程序所需的文件”,則會發生這種情況。
如果我選擇“此項目中的所有文件”,它工作正常。
我猜 Elmah 依賴於舊版本的 MVC 或其他東西——我怎樣才能在不上傳所有文件的情況下解決這個問題?
解決此類問題的最佳方法是什麼?
謝謝。
我在使用 MVC4 和為 .Net 4.5 建構的 Ninject 時遇到了同樣的問題
為了解決這個問題,我必須在我的 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舊版本而不是舊版本。