首页 文章

从2012年到2013年更新后无法加载文件或程序集'System.Web.Http 4.0.0

提问于
浏览
166

我按照升级进行了升级 . http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

我收到了错误 . 有没有其他人得到这个错误?

'/'应用程序中的服务器错误 . 无法加载文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一 . 定位的程序集的清单定义与程序集引用不匹配 . (来自HRESULT的异常:0x80131040)描述:在执行当前Web请求期间发生了未处理的异常 . 请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息 . 异常详细信息:System.IO.FileLoadException:无法加载文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一 . 定位的程序集的清单定义与程序集引用不匹配 . (来自HRESULT的异常:0x80131040)源错误:第48行:第49行:第50行:}第51行:第52行:protected void Application_BeginRequest(object sender,EventArgs e)源文件:d:\ SM \ 7.4Test \ WebAPIServerV2 \ ThirdPartyWebAPI \ Global.asax.cs行:50程序集加载跟踪:以下信息有助于确定无法加载程序集“System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”的原因 . ===预绑定状态信息===日志:DisplayName = System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35(完全指定)LOG:Appbase = file:/// D: /SM/7.4Test/WebAPIServerV2/ThirdPartyWebAPI/日志:初始PrivatePath = D:\ SM \ 7.4Test \ WebAPIServerV2 \ ThirdPartyWebAPI \ bin调用程序集:ThirdPartyWebAPI,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null . ===日志:此绑定在默认加载上下文中启动 . 日志:使用应用程序配置文件:D:\ SM \ 7.4Test \ WebAPIServerV2 \ ThirdPartyWebAPI \ web.config日志:使用主机配置文件:C:\ Users \ michalc \ Documents \ IISExpress \ config \ aspnet.config日志:使用机器配置来自C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ config \ machine.config的文件 . 日志:后策略引用:System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35日志:尝试下载新的URL文件:/// C:/Windows/Microsoft.NET/Framework/v4 .0.30319 / Temporary ASP.NET Files / root / 9184b2ea / c6d4b139 / System.Web.Http.DLL . 日志:尝试下载新的URL文件:/// C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files / root / 9184b2ea / c6d4b139 / System.Web.Http / System.Web.Http .DLL . 日志:尝试下载新的URL文件:/// D:/SM/7.4Test/WebAPIServerV2/ThirdPartyWebAPI/bin/System.Web.Http.DLL . 警告:比较程序集名称导致不匹配:主要版本错误:无法完成程序集的设置(hr = 0x80131040) . 探测终止 . 堆栈跟踪:[FileLoadException:无法加载文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一 . 定位的程序集的清单定义与程序集引用不匹配 . (来自HRESULT的异常:0x80131040)] d:\ SM \ 7.4Test \ WebAPIServerV2 \ ThirdPartyWebAPI \ Global.asax.cs中的ThirdPartyWebAPI.WebApiApplication.Application_Start():[HttpException(0x80004005):无法加载文件或程序集'系统 . Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一 . 定位的程序集的清单定义与程序集引用不匹配 . (来自HRESULT的异常:0x80131040)] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context,HttpApplication app)9935033 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext context,MethodInfo [] handlers)118 System.Web.HttpApplication.InitSpecial (HttpApplicationState状态,MethodInfo []处理程序,IntPtr appContext,HttpContext上下文)172 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext context)336 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)296 [HttpException(0x80004005) :无法加载文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一 . 定位的程序集的清单定义与程序集引用不匹配 . (来自HRESULT的异常:0x80131040)] System.Web.HttpRuntime.FirstRequestInit(HttpContext context)9913572 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context)254


版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.18408

27 回答

  • 2

    在我的情况下,我实际上完全错过了 web.config ,它具有适当的绑定重定向 . 恢复 web.config 解决了错误 .

  • 267

    对我来说,它只是在 生产环境 环境中崩溃,而不是在本地机器上崩溃;解决它的原因是删除/ bin文件夹的内容然后再次重新生成它 .

  • 15

    只是一个明显但可能有用的提示....请记住检查您在webconfig程序集绑定中指定的新版本是否与您在你的项目参考 . (也就是说,当我写这个...如果你最近在System.Web.Http上做了一个NUGet,这将是5.1.0.0

  • 0

    我有一个类似的问题 . 一切都在以前工作 . 它最初是使用Web窗体制作的,后来又为某些东西添加了Web API .

    • 尝试卸载,安装并重新安装Microsoft.AspNet.WebApi软件包 .

    • 尝试从解决方案中删除packages文件夹并让NuGet在VS中恢复 .

    • 尝试删除单个程序集引用(在“引用”下)并重新安装程序包 .

    • 尝试将绑定重定向添加到几个答案中提到的web.config中的5.2.3.0版本 . 没有什么对我有用 .

    在Visual Studio中,有效的是将发布配置文件设置从Release更改为Debug . 奇怪,但那是有效的 . 所以在这里分享 .

  • 0

    我通过reinstalling the NuGet package解决了这个问题,它纠正了破坏的依赖关系 . 从包管理器中运行:

    Update-Package Microsoft.AspNet.WebApi -reinstall
    
  • 1

    我没有什么,只是将开发 Bin 文件夹 DLLs 复制到在线部署 Bin 文件夹,它对我来说很好 .

  • 1

    使用“发布”功能部署到Azure时出现此问题 . 请记住清除目的地的文件 .

    Publish Settings -> File Publish Options drop down -> Check Remove additional files at destination

    这解决了我的问题,万一人们不得不像我一样去寻找这个 . 我的项目/解决方案中的所有内容都是相同的版本,而不是我正在部署的目的地 .

  • 3
    <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
    </dependentAssembly>
    
  • 82

    我通过在运行 nuget 之后恢复nuget对我的 web.config 所做的更改来解决了这个问题 . 将更改还原为以前的工作版本 .

    <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
      </dependentAssembly>
    
  • 0

    我只是在缺少的程序集上设置了 Copy Local = true ,这很有效 . 这当然是通过右键单击缺少的引用(在错误消息中说明)并选择属性来实现的;如下:

    enter image description here

    这应该解决一个问题,因为可能有多个程序集导致问题 - 我做的是我选择了所有程序集并右键单击它们;选定的属性;并将它们全部设置为Copy Local = true;然后重新发布 .

  • 0

    我可以通过在主应用程序的app.config中添加程序集引用来解决System.Net.HTTP的类似问题 .

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.1.1.1" newVersion="4.0.0.0" />
          </dependentAssembly></runtime>
    
  • 15

    当我安装Web Api 2.2帮助启动此错误 . 我把它添加到web.config,它解决了我的问题 .

    <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
      </dependentAssembly>
    
  • 0

    对于引用中的dll,将Specfic version标志从true更改为false

  • 0

    是什么解决了我的问题是重新安装 Microsoft ASP.NET Web API 2.2 Help Page 和Microsoft ASP.NET Web API 2.2 OWIN 包 . 我同时重新安装了两个,但我认为是前者修复了这个问题 .

    我尝试了这里提供的前几个解决方案,但没有帮助,然后我将我的依赖项与一个有效的项目(来自Pluralsight的一个课程)中的那些进行了比较,上面的两个依赖项是一个较低的版本(5.0.0) )所以我将它们更新到5.2.3并开始工作 .

  • 2

    ASP.NET版本:4.0.30319.18408属于.Net4.5,System.Web.Http Version = 4.0.0.0与.NET4.0兼容 . 所以你拥有的版本不兼容 . 您应该将System.Web.Http更新为版本5.0.0.0,它与.Net4.5兼容

  • 4

    解决此问题的正确解决方案是按照以下步骤操作

    . 如果您的旧版本为15.5.4,请更新Visual Studio(可选)

    • 从web.config中删除所有绑定重定向

    • 将此添加到csproj文件:

    <PropertyGroup>

    <AutoGenerateBindingRedirects>真</ AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>真</ GenerateBindingRedirectsOutputType>
    </的PropertyGroup>

    • Build .

    • 在bin文件夹中,应该有一个 (WebAppName).dll.config 文件 .

    • 它应该有重定向 . 将这些复制到web.config

    • 再次从csproj文件中删除上面的剪辑

    • 应该有用

    Detailed Blog

  • 0

    To resolve the Could not load file or assembly 'System.Web.Http' error use NuGet to install the Web API 2.1 WebHost.

    在参考文献的解决方案资源管理器中右键单击并选择管理nuget包 . (如果没有安装nuget)

    enter image description here

    在左侧的manage NuGet Packages窗口中单击Online,然后在右上角搜索Web Host并安装Microsoft ASP.NET Web API 2.1 Web Host . (安装完成后,安装按钮将变为绿色检查)

    之后,项目将重新加载,当它再次构建时,错误将得到解决,项目将调试并运行 . 错误将消失,您可能是'无法找到资源 . 只需附加网址(从localhost:52088 /到localhost:52088api / products)

    你的问题很好,帮助了我 .

    希望这个答案有帮助!

  • 2

    如果你 use several projects on a solution ,并将一个项目中的方法调用到另一个项目,请确保所有项目(称为项目和调用项目) use the unique 'System.Net.Http' version .

  • 2

    正如其他人所说的那样,只需使用nuget将MVC包重新安装到您的Web项目中,但请务必根据Web项目(例如单元测试)将MVC包添加到任何项目中 . 如果你单独构建每个包含的项目,你会看到女巫需要的更新 .

  • 1

    您需要添加程序集重定向:

    <configuration>
    
       ....
    
       <runtime>
          <assemblyBinding>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
          </assemblyBinding>
       </runtime>
    
       ...
    
    </configuration>
    

    最有可能你需要为webhosting等更多的程序集执行此操作 .

  • 58

    或者您可以从NuGet Package Manager Console执行此操作

    Install-Package Microsoft.AspNet.WebApi -Version 5.0.0
    

    然后,您将能够添加对System.Web.Http.WebHost 5.0的引用

  • 0

    我有同样的问题,重新安装包不起作用 .

    我的应用程序在LocalIIS(不是IIS EXPRESS)中运行 . 我启用程序集加载跟踪并找出它想从负载下方加载System.Web.Http加载 . 所以 remove all catch folders 在里面 .

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files[my application]

  • 0

    是!!!

    Install-Package Microsoft.AspNet.WebApi -Version 5.0.0
    

    它在我的情况下工作正常.... thnkz

  • 1

    这可能对某人有帮助 .

    我决定使用MVC4应用程序 .

    run project, worked

    然后安装几个包,像,
    Microsoft ASP.NET WEB API 2.2 (4 packages)
    Microsoft ASP.NET WEB API 2.2 Help Page
    Microsoft ASP.NET WEB API 2.2 OWIN

    run project, same error as mentioned in question

    Solution:

    web.config

    <dependentAssembly>
          <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.2.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.2.3.0" />
     </dependentAssembly>
    

    Problem Solved


    但是,发现了一些 hotfix 错误,要解决它,请转到MVC4项目的 VIEW 文件夹,找到 second web.config 文件并将版本从 2.0.0.0 更改为 3.0.0.0 ,如下所示 .


    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
          <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
      </configSections>
    

  • 0
    Installing NuGet package ASP.NET.MVC solved the issue for me. 
     To install package.
     - Right click on project 
     - Select "Manage NuGet Packages"
     - Select Online->Nuget.org from left menu
     - select "Microsoft ASP.NET MVC"
     - Click Install
    
     If you have already installed package earlier, please update the package by selecting Updates from left menu and then selecting "Microsoft ASP.NET" and click Update.
    

    enter image description here

    enter image description here

  • 0

    我找到了解决方案!删除项目目录中名为package的文件夹,然后重建以运行它 .

  • 1

    我从WCF服务获得了这个 . 对我来说(因为问题显示在本地开发中),我只需删除解决方案下bin文件夹的内容 . 重建工作再次正常 .

相关问题