我有一个小的MVC应用程序,我用它来进行练习,但现在每次我尝试调试时都会遇到一个错误:
Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies.
The system cannot find the path specified.
我已经通过谷歌搜索但找不到解决方案。我正在使用.NET 4.5。
这不可能是DLL文件的问题,因为我正在使用.NET 4.5。
我有一个小的MVC应用程序,我用它来进行练习,但现在每次我尝试调试时都会遇到一个错误:
Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies.
The system cannot find the path specified.
我已经通过谷歌搜索但找不到解决方案。我正在使用.NET 4.5。
这不可能是DLL文件的问题,因为我正在使用.NET 4.5。
编辑 >>>
对于 Visual Studio 2013 及以上版本,第二个步骤应为:
删除所有关于 System.Net.*
的代码引用。
在包管理器控制台中,运行以下命令:
Install-Package Microsoft.AspNet.WebApi.Client
清理并重建您的项目。
Web.Config
中的bindingRedirect
,将System.Net.Http.Formatting
和System.Web.Http
的版本更新为上述命令安装的新版本后,此解决方案起作用了...即它从<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
变成了<bindingRedirect oldVersion="0.0.0.0-4.0.30319" newVersion="4.0.30319"/>
。 - Serj Sagan <dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
</dependentAssembly>
在我的web.config文件中,我把它删除以使其正常工作。我安装了其他一些包,然后又将其删除导致了这个问题。
user3919888指引了我正确的方向,但我需要在包管理器控制台中运行Update-Package -reinstall Microsoft.AspNet.WebApi.Client
。仅进行基本安装无法识别问题,但可以识别已经安装该软件包并且不会覆盖它。
我发布这个答案是因为这种情况很少发生,以至于每次我都要通过谷歌并访问这个页面才能想起我上次做过的事情。
web.config
中删除以下行解决了我的问题。请注意,在此项目中,我没有使用WebApi组件。因此,对于其他人来说,这个解决方案可能不起作用。 <dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
对于那些同时使用.NET Standard 项目和.NET Framework 项目的人:
在.NET Standard中,包含在.NET Standard项目中的软件包将正确地在其他.NET Core和.NET Standard项目中使用。
在.NET Framework中,如果您从.NET Framework(MVC)项目引用.NET Standard项目,则需要手动下载并安装相同的NuGet软件包。
所以,我的问题的答案是我需要在Web项目(.NET Framework)中下载并安装Microsoft.AspNet.WebApi.Client
,这个Web项目在使用需要Microsoft.AspNet.WebApi.Client
的.NET Standard项目。实际上,我已经安装了它,但版本不同。
我仅仅是为了让其他人看到这个答案,虽然它不能直接回答OP的问题,但这确实节省了我的时间,因为我首先检查了这个而不是做最受欢迎的答案。
System.Net.*
的代码引用。Microsoft.AspNet.WebApi
及其依赖项的软件包。Microsoft.AspNet.WebApi
及其依赖项的软件包。对我而言,这个问题是由于添加Microsoft.AspNet.WebApi.Client包后,在Web.config中缺少程序集绑定条目(System.Net.Http.Formatting)所致。
我检查了我的Microsoft.AspNet.WebApi.Client版本,并将以下绑定添加到Web.config:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
根据您所拥有的 WebApi.Client 版本,在绑定重定向中更改版本。
web.config
中的几行额外代码。 - Lazlow在我的情况下,以上解决方案都没有奏效。我通过在Visual Studio中右键单击引用
System.Net.Http.Formatting
并将属性Copy Local设置为true来解决问题。
希望这对您有所帮助。