服务器错误/应用程序出现以下错误消息:更改为MVC5后无法加载文件或程序集'Microsoft.Web.Infrastructure

问题描述

最近,我们将MVC4更新为MVC5。启动Web服务时,我有一个用于报告目的的Web服务,出现以下错误

[FileNotFoundException: Could not load file or assembly 'Microsoft.Web.Infrastructure,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.WebPages.PreApplicationStartCode.Start() +0
   System.Web.Mvc.PreApplicationStartCode.Start() +37

[InvalidOperationException: The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure,PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
   System.Web.Compilation.BuildManager.InvokePreStartinitMethodscore(ICollection`1 methods,Func`1 setHostingEnvironmentCultures) +850
   System.Web.Compilation.BuildManager.InvokePreStartinitMethods(ICollection`1 methods) +162
   System.Web.Compilation.BuildManager.CallPreStartinitMethods(String preStartinitListPath,Boolean& isRefAssemblyLoaded) +128
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +170
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager,IApplicationHost appHost,IConfigMapPathFactory configMapPathFactory,HostingEnvironmentParameters hostingParameters,PolicyLevel policyLevel,Exception appDomainCreationException) +820

[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure,PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
   System.Web.HttpRuntime.FirstRequestinit(HttpContext context) +523
   System.Web.HttpRuntime.EnsureFirstRequestinit(HttpContext context) +107
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context) +688

我没有在我的服务中引用此 Microsoft.Web.Infrastructure.dll ,但是升级到MVC5后出现此dll问题。有帮助吗?

解决方法

Microsoft.Web.Infrastructure.dll 是密钥库。您应该添加此选项,这可能是内部需要/引用的一项。
您可以在 packages.config 文件和web.config
中检查所有dll引用。
或者它可能出现在本地,但是您没有将它在其属性中将本地复制到True