Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS2017RC3 - Assembly conflicts because of the same name #1386

Closed
JamesNK opened this issue Jan 31, 2017 · 31 comments
Closed

VS2017RC3 - Assembly conflicts because of the same name #1386

JamesNK opened this issue Jan 31, 2017 · 31 comments
Assignees
Milestone

Comments

@JamesNK
Copy link
Member

JamesNK commented Jan 31, 2017

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?

@davkean
Copy link
Member

davkean commented Feb 1, 2017

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

@nguerrera
Copy link
Contributor

This is dotnet/sdk#364

Cc @mattwar

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

@mattwar
Copy link
Contributor

mattwar commented Feb 1, 2017

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.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 2, 2017

Ok, I'll try it tonight

@JamesNK
Copy link
Member Author

JamesNK commented Feb 2, 2017

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 ==========

@davkean
Copy link
Member

davkean commented Feb 2, 2017

@mattwar Bear in mind that externalscrazy Kiwis are running RC3.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 2, 2017

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

@davkean
Copy link
Member

davkean commented Feb 2, 2017

Fixed.

@srivatsn srivatsn added this to the 1.0 RTM milestone Feb 2, 2017
@srivatsn srivatsn added the Bug label Feb 2, 2017
@JamesNK
Copy link
Member Author

JamesNK commented Feb 6, 2017

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.

@davkean
Copy link
Member

davkean commented Feb 8, 2017

@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?

@dsplaisted
Copy link
Member

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

@JamesNK
Copy link
Member Author

JamesNK commented Feb 9, 2017

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 JamesNK/Newtonsoft.Json@bd3d201#diff-7943d585b13cd19598be20000ad7867fR4

@JamesNK
Copy link
Member Author

JamesNK commented Feb 9, 2017

@JamesNK
Copy link
Member Author

JamesNK commented Feb 9, 2017

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.

@davkean
Copy link
Member

davkean commented Feb 9, 2017

What do you mean by "corrupted"?

@JamesNK
Copy link
Member Author

JamesNK commented Feb 9, 2017

https://github.com/JamesNK/Newtonsoft.Json/blob/b1b8c67ab6a0e847ecdb3a49bb45121fa09d7f5d/Src/Newtonsoft.Json/Newtonsoft.Json.Dotnet.csproj

git still thinks the new VS2017 csproj files are binary for some reason 🤷‍♂️

@srivatsn srivatsn assigned dsplaisted and unassigned mattwar Feb 9, 2017
@dsplaisted
Copy link
Member

@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 #1532 for this.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 11, 2017

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

@JamesNK
Copy link
Member Author

JamesNK commented Feb 11, 2017

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.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 11, 2017

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

@dsplaisted
Copy link
Member

@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.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 16, 2017

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.

@davkean
Copy link
Member

davkean commented Feb 16, 2017

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.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 16, 2017

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

@JamesNK
Copy link
Member Author

JamesNK commented Feb 16, 2017

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.

@davkean
Copy link
Member

davkean commented Feb 16, 2017

Yeah that's #1242, will be fixed in the next public build. Should unfreeze after a while.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 16, 2017

build.zip

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

@davkean
Copy link
Member

davkean commented Feb 16, 2017

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 microsoft/vstest#393.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 16, 2017

Ok! Closed

@JamesNK JamesNK closed this as completed Feb 16, 2017
@davkean
Copy link
Member

davkean commented Feb 16, 2017

I filed dotnet/msbuild#1712 against MSBuild because I hate this warning.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 16, 2017

❤️

@drewnoakes drewnoakes removed the Bug label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants