这个错误刚刚开始发生。使用Visual Studio 2017,System.Net.Http.Formatting问题已经持续了好几年。
我只在网页上看到此消息:
无法加载文件或程序集“System.Net.Http.Formatting-Cosmo”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)
跟踪追溯:
=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http.Formatting-Cosmo
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Net.Http.Formatting-Cosmo | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/George/OneDrive/SignupList/SignupList/
LOG: Initial PrivatePath = C:\Users\George\OneDrive\SignupList\SignupList\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\George\OneDrive\SignupList\SignupList\web.config
LOG: Using host configuration file: C:\Users\George\OneDrive\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/George/AppData/Local/Temp/Temporary ASP.NET Files/vs/6cc2628d/51b3c1a6/System.Net.Http.Formatting-Cosmo.DLL.
LOG: Attempting download of new URL file:///C:/Users/George/AppData/Local/Temp/Temporary ASP.NET Files/vs/6cc2628d/51b3c1a6/System.Net.Http.Formatting-Cosmo/System.Net.Http.Formatting-Cosmo.DLL.
LOG: Attempting download of new URL file:///C:/Users/George/OneDrive/SignupList/SignupList/bin/System.Net.Http.Formatting-Cosmo.DLL.
WRN: Comparing the assembly name resulted in the mismatch: NAME
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
似乎停止尝试查找System.Net.Http.Formatting,它在配置中具有正确的DLL版本。
<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>
我使用的是ASP.NET而不是MVC,我不知道为什么需要System.Net.Http.Formatting。 Cosmo是我的电脑名称。我希望-Cosmo不是问题,我不明白为什么会这样。
我做了Stack Overflow中前4年帖子中提到的所有内容 - Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies. The system cannot find the path specified 没有解决它。我发现了其他帖子并使用了Microsoft.AspNet.WebApi.Core V 5.2.4,它将System.Net.Http.Formatting V 5.2.3.0。
System.Net.Http.Formatting Reference上的Local Copy属性设置为True。她重新获得的所有包裹。该项目已重新初始化。我已经尝试了所有可以找到的建议。
没有Microsoft.AspNet.WebApi.Core,如果我编译我得到编译错误抱怨System.Net.Http.Formatting缺失。添加Core返回,错误消失,编译正常。由于依赖性,我还必须删除并重新添加Microsoft.AspNet.WebApi.WebHost和Microsoft.AspNet.WebApi.Core。运行它时的网页会给出错误以及项目中每个ASPX文件的顶行。
我也有Newtonsoft.Json,我见过这与此有关。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Telerik.Web.UI" publicKeyToken="121fae78165ba3d4" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2014.3.1209.45" newVersion="2014.3.1209.45" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Apis" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.25.0.0" newVersion="1.25.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.25.0.0" newVersion="1.25.0.0" />
</dependentAssembly>
<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>
</assemblyBinding>
</runtime>
程序集正在寻找System.Net.Http.Formatting-Cosmo并尝试下载它。 System.Net.Http.Formatting正在bin中,我甚至添加了System.Net.Http.Formatting-Cosmo以防万一。版本匹配。为什么找不到bin DLL? -Cosmo有问题吗?
令人费解。
乔治
答案 0 :(得分:5)
现在已修复,但我不确定它是如何修复的,因为我尝试了很多不同的东西,包括更新Visual Studio和摆脱旧的Visual Studios,它们没有解决问题,但确实改变了一点。 / p>
我注意到System.Net.Http.Formatting.dll的版本为5.2.60201.0。环顾四周,我看到Microsoft.AspNet.WebApi.Client也可能参与其中。
使用NuGet Package Manager,我删除了Microsoft.AspNet.WebApi.WebHost,Microsoft.AspNet.WebApi.Core和Microsoft.AspNet.WebApi.Client。然后我重新添加了所有3个版本的最新版本5.2.4。客户端包位于5.2.2。
现在,Web.config中System.Net.Http.Formatting的dependentAssembly有newVersion =“5.2.4.0”。 DLL上的版本是5.2.60201.0,所以我期待它看到问题,但它的工作原理。寻找System.Net.Http.Formatting版本5.2.4.0似乎找到5.2.60201.0就好了,而5.2.3.0则不行。
就像我认为更好地理解它一样,它运作良好。肯定是一种学习经历。
最后我相信,
应该都是NuGet Manager中依赖项中确认的相同版本。