【问题标题】:There was a conflict between "System.Net.Http"“System.Net.Http”之间存在冲突
【发布时间】:2018-07-01 12:57:28
【问题描述】:

当我尝试构建我的 Asp .Net Core (1.1.2) 应用程序时,我收到以下警告:

发现不同版本的“System.Net.Http”之间存在无法解决的冲突。当日志详细程度设置为详细时,这些引用冲突会列在构建日志中。

这会变成运行时错误,因此我正在尝试修复此警告...

我在 Visual Studio 中打开了详细日志记录,我在构建输出窗口中看到了这一点:

There was a conflict between "System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    "System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
    References which depend on "System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Users\mdepouw\.nuget\packages\system.net.http\4.3.1\ref\net46\System.Net.Http.dll].
        C:\Users\mdepouw\.nuget\packages\system.net.http\4.3.1\ref\net46\System.Net.Http.dll
          Project file item includes which caused reference "C:\Users\mdepouw\.nuget\packages\system.net.http\4.3.1\ref\net46\System.Net.Http.dll".
            System.Net.Http
    References which depend on "System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\System.Net.Http.dll].
        C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.applicationinsights.aspnetcore\2.1.1\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll
          Project file item includes which caused reference "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.applicationinsights.aspnetcore\2.1.1\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll".
            C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.applicationinsights.aspnetcore\2.1.1\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll
        C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Services.Common.dll
          Project file item includes which caused reference "C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Services.Common.dll".
            C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Services.Common.dll
        C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Persistence.MarkLogic.dll
          Project file item includes which caused reference "C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Persistence.MarkLogic.dll".
            C:\Users\mdepouw\Source\Repos\MyProject\MyProject.Services.Common\bin\x64\Debug\MyProject.Services.Common.dll

          ... more dlls that reference 4.1.1.2

依赖关系


我不明白告诉我哪些“参考”依赖于System.Net.Http, Version=4.1.1.0 的部分。我正在阅读它,因为它取决于它本身。我误会了什么?

我没有通过程序集引用或 Nuget 引用直接引用 System.Net.Http。

另外,“C:\Users\mdepouw.nuget\packages\system.net.http\4.3.1\ref\net46\System.Net.Http.dll”中的文件版本为4.1.1.0。

【问题讨论】:

  • 这意味着您使用的两个不同的包(或您链接的解决方案中的其他项目)引用了 System.Net.Http 程序集的不同版本。查看 Dependencies > NETStandard 2.0 或 .NET Core 2.0(或仅当您只有一个目标时的“依赖项”)并列出依赖项。如果您使用“Search Solution Explorer”字段并在其中键入“System.Net.Http”,则更容易它并查看哪些库依赖于它
  • 当你混合一些东西时经常会发生这种情况,比如一些旧的 beta 或 rc 与 release 或 ASP.NET Core 1.x 与 2.x

标签: visual-studio asp.net-core msbuild nuget


【解决方案1】:

更新:原始修复适用于我的 WebApi,但不适用于查看 MVC 页面。我开始收到另一个运行时异常:Can not find assembly file Microsoft.CSharp.dll。

我将<DependsOnNETStandard>true</DependsOnNETStandard> 更改为<DependsOnNETStandard>netstandard1.6</DependsOnNETStandard> 并解决了问题。

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>
    <AssemblyName>MyProject</AssemblyName>
    <Platforms>AnyCPU;x64</Platforms>
    <DependsOnNETStandard>netstandard1.6</DependsOnNETStandard>
  </PropertyGroup>
...
</Project>

原答案:

我为每个this GitHub 问题添加了&lt;DependsOnNETStandard&gt;true&lt;/DependsOnNETStandard&gt;,我的构建警告消失了,我的运行时错误也消失了。

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>
    <AssemblyName>MyProject</AssemblyName>
    <Platforms>AnyCPU;x64</Platforms>
    <DependsOnNETStandard>true</DependsOnNETStandard>
  </PropertyGroup>
...
</Project>

【讨论】:

  • 好点。我想等一会儿,以防它真正起作用或有人有更好的主意!
【解决方案2】:

我不明白告诉我哪些“参考”取决于 System.Net.Http,版本 = 4.1.1.0 的部分。我正在阅读它,因为它取决于它本身。我误会了什么?

那是因为 Microsoft.AspNetCore 的一个依赖项拖入了 NETStandard.Library 1.6,这会添加大量 System.* 依赖项:

“System.Net.Http”之间存在冲突

这是一个关于 .NET core 的已知问题:

System.Net.Http package 4.3.2 - redirect to 4.2.0.0, assembly loading failure

此问题将在下一个版本 2.1.0 中修复。

Tornhoof 提供的当前解决方法:

<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.2" newVersion="4.1.1.2" />
  </dependentAssembly>      
</assemblyBinding>

它使用构建扩展目录中的 dll,而不是 Nuget 中的。

【讨论】:

  • 感谢 Leo 的回复。我的应用程序是 ASP.Net Core 1.1.2 应用程序;不是2.0。我已经用我的依赖项更新了我的问题。
猜你喜欢
  • 2018-07-29
  • 1970-01-01
  • 2019-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多