Project-system: VS2017RC3 - Assembly conflicts because of the same name

Created on 31 Jan 2017  路  31Comments  路  Source: dotnet/project-system

I have an interesting situation: I have a project called Newtonsoft.Json that I want to test in netcoreapp1.0, but the Microsoft.NET.Test.Sdk package that I have to depend on to run tests has a dependency on a NuGet package called Newtonsoft.Json.

I get this warning when I build in VS2017RC3:

Warning MSB3243 No way to resolve conflict between "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null". Choosing "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.

And lots of this error:

error CS0433: The type 'JsonConstructorAttribute' exists in both 'Newtonsoft.Json, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

How do I tell the Roslyn/msbuild/.NET Core that I want the referenced Newtonsoft.Json project to be used?

Bug

Most helpful comment

I filed https://github.com/Microsoft/msbuild/issues/1712 against MSBuild because I hate this warning.

All 31 comments

@nguerrera @dsplaisted What's a recommendation for James here? He basically needs our "project overrides package ref" feature that we haven't written yet.

This is https://github.com/dotnet/sdk/issues/364

Cc @mattwar

There's a workaround shown there. Try it with Foo replaced by Newtonsoft.Json.

dotnet/sdk#364 does not repro with more recent VS. Possibly this is already solved too. The repro I tried had a referenced project building a fake Newtonsof.Json.dll and nuget reference of the actual Newtonsof.Json.dll. The project wins over the nuget package in the build and in the IDE.

Ok, I'll try it tonight

I get the same warnings and error messages after adding the XML work around.

<Project Sdk="Microsoft.NET.Sdk">
  <Target Name="WorkAroundPackageAndProjectReferenceConflict" BeforeTargets="ResolveLockFileReferences">
    <ItemGroup>
      <ResolvedCompileFileDefinitions
          Remove="@(ResolvedCompileFileDefinitions)"
          Condition="'%(ResolvedCompileFileDefinitions.Filename)' == 'Newtonsoft.Json'" />
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <TargetFrameworks>netcoreapp1.0</TargetFrameworks>
    <!--<TargetFrameworks>net45;net40;net35;net20;netcoreapp1.0</TargetFrameworks>-->
    <VersionPrefix>10.0.1</VersionPrefix>
    <VersionSuffix>beta1</VersionSuffix>
    <Authors>James Newton-King</Authors>
    <Company>Newtonsoft</Company>
    <NeutralLanguage>en-US</NeutralLanguage>
    <Description>Json.NET is a popular high-performance JSON framework for .NET</Description>
    <Copyright>Copyright 漏 James Newton-King 2008</Copyright>
    <Summary>Json.NET is a popular high-performance JSON framework for .NET</Summary>
    <AssemblyName>Newtonsoft.Json.Tests</AssemblyName>
    <DebugType>portable</DebugType>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Dotnet.csproj" />
    <PackageReference Include="NUnit" Version="3.6.0" />
  </ItemGroup>
  <ItemGroup Condition="'$(TargetFramework)'=='net45'">
    <Reference Include="Microsoft.CSharp" />
    <PackageReference Include="Autofac" Version="4.0.0-rc2-240" />
    <PackageReference Include="FSharp.Core" Version="4.0.0.1" />
    <PackageReference Include="System.Buffers" Version="4.0.0" />
    <PackageReference Include="System.Collections.Immutable" Version="1.1.37" />
    <Reference Include="System.Web" />
    <Reference Include="System.Data.Linq" />
    <Reference Include="System.Data.Entity" />
    <Reference Include="System.ComponentModel.DataAnnotations" />
    <Reference Include="System.Web.Extensions" />
    <Reference Include="System.Data.DataSetExtensions" />
  </ItemGroup>
  <PropertyGroup Condition="'$(TargetFramework)'=='net45'">
    <DefineConstants>
    </DefineConstants>
  </PropertyGroup>
  <ItemGroup Condition="'$(TargetFramework)'=='net40'">
    <Reference Include="Microsoft.CSharp" />
    <PackageReference Include="FSharp.Core" Version="4.0.0.1" />
    <Reference Include="System.Web" />
    <Reference Include="System.Data.Linq" />
    <Reference Include="System.Data.Entity" />
    <Reference Include="System.ComponentModel.DataAnnotations" />
    <Reference Include="System.Web.Extensions" />
    <Reference Include="System.Data.DataSetExtensions" />
  </ItemGroup>
  <PropertyGroup Condition="'$(TargetFramework)'=='net40'">
    <DefineConstants>NET40</DefineConstants>
  </PropertyGroup>
  <ItemGroup Condition="'$(TargetFramework)'=='net35'">
    <Reference Include="System.Web" />
    <Reference Include="System.Data.Linq" />
    <Reference Include="System.Data.Entity" />
    <Reference Include="System.ComponentModel.DataAnnotations" />
    <Reference Include="System.Web.Extensions" />
    <Reference Include="System.Data.DataSetExtensions" />
  </ItemGroup>
  <PropertyGroup Condition="'$(TargetFramework)'=='net35'">
    <DefineConstants>NET35</DefineConstants>
  </PropertyGroup>
  <ItemGroup Condition="'$(TargetFramework)'=='net20'">
    <Reference Include="System.Web" />
  </ItemGroup>
  <PropertyGroup Condition="'$(TargetFramework)'=='net20'">
    <DefineConstants>NET20</DefineConstants>
  </PropertyGroup>
  <ItemGroup Condition="'$(TargetFramework)'=='netcoreapp1.0'">
    <PackageReference Include="FSharp.Core" Version="4.0.1.7-alpha" />
    <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
    <PackageReference Include="System.Runtime.Serialization.Xml" Version="4.1.1" />
    <PackageReference Include="System.Runtime.Serialization.Json" Version="4.0.2" />
    <PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.1.1" />
    <PackageReference Include="System.Xml.XmlSerializer" Version="4.0.11" />

    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
  </ItemGroup>
  <PropertyGroup Condition="'$(TargetFramework)'=='netcoreapp1.0'">
    <OutputType>Exe</OutputType>
    <DefineConstants>NETSTANDARD1_0;DNXCORE50;PORTABLE</DefineConstants>
  </PropertyGroup>
</Project>

Output

1>------ Build started: Project: Newtonsoft.Json.Dotnet, Configuration: Debug Any CPU ------
1>Newtonsoft.Json.Dotnet -> C:\Development\Source\Newtonsoft.Json\Src\Newtonsoft.Json\bin\Debug\net45\Newtonsoft.Json.dll
1>Newtonsoft.Json.Dotnet -> C:\Development\Source\Newtonsoft.Json\Src\Newtonsoft.Json\bin\Debug\net40\Newtonsoft.Json.dll
1>Newtonsoft.Json.Dotnet -> C:\Development\Source\Newtonsoft.Json\Src\Newtonsoft.Json\bin\Debug\net35\Newtonsoft.Json.dll
1>Newtonsoft.Json.Dotnet -> C:\Development\Source\Newtonsoft.Json\Src\Newtonsoft.Json\bin\Debug\net20\Newtonsoft.Json.dll
1>Newtonsoft.Json.Dotnet -> C:\Development\Source\Newtonsoft.Json\Src\Newtonsoft.Json\bin\Debug\netstandard1.0\Newtonsoft.Json.dll
1>Newtonsoft.Json.Dotnet -> C:\Development\Source\Newtonsoft.Json\Src\Newtonsoft.Json\bin\Debug\portable-net45+win8+wpa81+wp8\Newtonsoft.Json.dll
2>------ Build started: Project: Newtonsoft.Json.Tests.Dotnet, Configuration: Debug Any CPU ------
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1912,5): warning MSB3243: No way to resolve conflict between "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null". Choosing "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1912,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
2>Documentation\Samples\Serializer\JsonConstructorAttribute.cs(37,41,37,65): error CS0433: The type 'JsonConstructorAttribute' exists in both 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
2>JsonValidatingReaderTests.cs(49,52,49,71): error CS0433: The type 'ValidationEventArgs' exists in both 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
2>Schema\JsonSchemaGeneratorTests.cs(47,43,47,53): error CS0433: The type 'Extensions' exists in both 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
2>Serialization\SerializationErrorHandlingTests.cs(47,54,47,68): error CS0433: The type 'ErrorEventArgs' exists in both 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
2>JsonTextWriterTest.cs(1862,54,1862,64): error CS0433: The type 'JsonWriter' exists in both 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
2>JsonTextWriterTest.cs(1695,41,1695,55): error CS0433: The type 'JsonTextWriter' exists in both 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

...

2>Serialization\JsonSerializerTest.cs(10068,10,10068,22): error CS0433: The type 'JsonProperty' exists in both 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
2>Done building project "Newtonsoft.Json.Tests.Dotnet.csproj" -- FAILED.
========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========

@mattwar Bear in mind that ~externals~crazy Kiwis are running RC3.

Hey, you can't call us externals. That's our word.

Fixed.

Is this a bug that will require an updated version of VS2017?

Right now this is blocking me from porting Newtonsoft.Json from project.json to csproj.

@JamesNK We can't repro the bug right now. @dsplaisted's going to spend a little bit of time looking into it.

Have you tried the latest RC build?

@JamesNK Hi James, is this the branch you're working on and encountering these issues?: https://github.com/JamesNK/Newtonsoft.Json/tree/vs2017

Have you tried the latest RC build?

Yes I installed it last night. I believe the version number was updated in the sln file here https://github.com/JamesNK/Newtonsoft.Json/commit/bd3d2010d80605370d80c25c2e84311ea2422259#diff-7943d585b13cd19598be20000ad7867fR4

@JamesNK Hi James, is this the branch you're working on and encountering these issues?: https://github.com/JamesNK/Newtonsoft.Json/tree/vs2017

Yes it is. Add netcoreapp1.0 at https://github.com/JamesNK/Newtonsoft.Json/blob/bd3d2010d80605370d80c25c2e84311ea2422259/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Dotnet.csproj#L4 to reproduce it

Hmmm, although I think I still need to update the test project csproj to only include the NUnit package when the target isn't netcoreapp1.0. My csproj files were corrupted and I had to recreate them last night. I don't know if that will effect the bug.

What do you mean by "corrupted"?

@JamesNK At one point we had issues where we would corrupt the encoding of .csproj files. That may have been what happened to you. I gave up on trying to fix them and did a new migrate from scratch.

The way this is supposed to work is that the ProjectReference should replace the PackageReference to Newtonsoft.Json. This wasn't happening because the project name was Newtonsoft.Json.Dotnet.csproj, so it was assuming that the package ID for the project would be Newtonsoft.Json.Dotnet. You can specify the package ID and version (so you don't get downgrade warnings) by adding the following properties to your project:

    <Version>9.0.3</Version>
    <PackageId>Newtonsoft.Json</PackageId>

This fixes the issue for command-line restore and build. However, the PackageId property isn't being respected when Visual Studio runs the restore, so in VS you would still see the same issues. I've filed https://github.com/dotnet/roslyn-project-system/issues/1532 for this.

I probably lost PackageId when my file corrupted and I rebuilt it.

Ok, this is successfully compiling https://github.com/JamesNK/Newtonsoft.Json/commits/vs2017

However I am getting errors in VS when a file is open. I'll post details in a bit.

Hmmm, the errors that I'm getting when a file is open seem to have disappeared. Maybe adding PackageId fixed it.

@JamesNK Should we consider this fixed? I'm able to open your latest code and build successfully in VS. When #1532 is fixed, you should be able to remove the WorkAroundPackageAndProjectReferenceConflict target.

Test explorer isn't showing me any of your tests, but that seems like a separate issue.

Consider it fixed.

One last question - Is there a way to suppress this warning:

warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.

No, you suppress it by fixing it. :)

This is saying "one of your references is referencing a dll that is higher than what you are referencing". Post a diagnostic log and I can tell what it is.

The issue is the Newtonsoft.Json reference. How do I get the diagnostic log?

Do you mean the build output window content with the level set to diagnostic? I tried building with that but VS froze with the CPU spinning at 20%. Might be a bug there.

Yeah that's https://github.com/dotnet/roslyn-project-system/issues/1242, will be fixed in the next public build. Should unfreeze after a while.

build.zip

Log attached. I think some of the first build is truncated.

Relevant portion:

 There was a conflict between "Microsoft.Extensions.DependencyModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" and "Microsoft.Extensions.DependencyModel, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60".
2>            "Microsoft.Extensions.DependencyModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" was chosen because it was primary and "Microsoft.Extensions.DependencyModel, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" was not.
2>            References which depend on "Microsoft.Extensions.DependencyModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" [C:\Users\James\.nuget\packages\microsoft.extensions.dependencymodel\1.0.0\lib\netstandard1.6\Microsoft.Extensions.DependencyModel.dll].
2>                C:\Users\James\.nuget\packages\microsoft.extensions.dependencymodel\1.0.0\lib\netstandard1.6\Microsoft.Extensions.DependencyModel.dll
2>                  Project file item includes which caused reference "C:\Users\James\.nuget\packages\microsoft.extensions.dependencymodel\1.0.0\lib\netstandard1.6\Microsoft.Extensions.DependencyModel.dll".
2>                    C:\Users\James\.nuget\packages\microsoft.extensions.dependencymodel\1.0.0\lib\netstandard1.6\Microsoft.Extensions.DependencyModel.dll
2>            References which depend on "Microsoft.Extensions.DependencyModel, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" [].
2>                C:\Users\James\.nuget\packages\microsoft.testplatform.testhost\15.0.0-preview-20170210-02\lib\netstandard1.5\Microsoft.TestPlatform.CrossPlatEngine.dll
2>                  Project file item includes which caused reference "C:\Users\James\.nuget\packages\microsoft.testplatform.testhost\15.0.0-preview-20170210-02\lib\netstandard1.5\Microsoft.TestPlatform.CrossPlatEngine.dll".
2>                    C:\Users\James\.nuget\packages\microsoft.testplatform.testhost\15.0.0-preview-20170210-02\lib\netstandard1.5\Microsoft.TestPlatform.CrossPlatEngine.dll
2>                    C:\Users\James\.nuget\packages\microsoft.testplatform.testhost\15.0.0-preview-20170210-02\lib\netstandard1.5\testhost.dll
2>        C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1956,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.

This is https://github.com/Microsoft/vstest/issues/393.

Ok! Closed

I filed https://github.com/Microsoft/msbuild/issues/1712 against MSBuild because I hate this warning.

鉂わ笍

Was this page helpful?
0 / 5 - 0 ratings