Runtime: System.Xml.ReaderWriter 4.3.0 not compatible with .NET Framework 4.6?

Created on 28 Nov 2016  路  19Comments  路  Source: dotnet/runtime

When updating our .NET Framework 4.6 projects to NuGet package System.Xml.ReaderWriter 4.3.0 it works on some machines, but fails to build on others with an error:

CS1703: Multiple assemblies with equivalent identity have been imported: '...MySolution\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\Facades\System.Xml.ReaderWriter.dll'. Remove one of the duplicate references.

Downgrading System.Xml.ReaderWriter to 4.0.11 everything works fine on all machines.

Working machines are running VS2015, the other machine has got a .NET Framework 4.6.2 SDK installed.

area-System.Xml bug

Most helpful comment

I was having the same problem with the same package. Building on my machine (VS 2015 Update 3) but failing on my build server (Build Tools 2015).

Fixed when I updated my build server to use the Build Tools 2015 Update 3.

All 19 comments

Let's try to rule out misconfiguration of your project -- can you try to repro on HelloWolrd app?

Installing System.Xml.ReaderWriter 4.3.0 and System.Text.Encoding.CodePages 4.3.0 together in a .NET Framework 4.6 project doesn't work on some machines with only the SDK installed.

Downgrading System.Text.Encoding.CodePages does not work.
Downgrading System.Xml.ReaderWriter to 4.0.11 works.
Changing the target framework to 4.5 doesn't work because System.Text.Encoding.CodePages doesn't support it.

This is how I've tested:

  • I've created a new .NET 4.6 library project, added only System.Xml.ReaderWriter 4.3.0 and it built.
  • Then I've added Microsoft.CodeAnalysis 1.3.2 with all its dependencies and it failed.
  • Then I've updated everything to latest and it still failed.
  • Then I've removed all Microsoft.CodeAnalysis.* packages and it still failed.
  • Then I've removed Microsoft.Composition 1.0.30, System.Reflection.Metadata 1.4.1 and System.Collections.Immutable 1.3.0 and it still failed. All remaining packages have version 4.3.0.
  • Then I've started to remove System.* packages in (almost) alphabetical order. It started to build when I uninstalled System.Text.Encoding.CodePages 4.3.0.
  • I've reinstalled System.Text.Encoding.CodePages 4.3.0 and it failed again.
  • So I've skipped System.Text.Encoding.CodePages 4.3.0 and removed the remaining System.* packages except the System.Xml.* packages and it still failed.
  • Then I've removed the System.Xml.* packages except System.Xml.ReaderWriter and it failed with only System.Xml.ReaderWriter 4.3.0 and System.Text.Encoding.CodePages 4.3.0 installed.

Another test I did:

Setting the target framework version to 4.5 on the empty project and then adding System.Xml.ReadWriter 4.3.0 adds a reference to the System.Xml reference assembly. Then switching the target framework to 4.6 and installing System.Text.Encoding.CodePages 4.3.0 adds a reference to the packaged assembly and builds (with a warning in VS2015 about a NuGet package targeting the wrong framework version, but no warning from MSBuild on the other machine).

Then doing a

PM> Update-Package -Reinstall

the build breaks again (with or without the reference to the System.Xml reference assembly).

@karelz, any thoughts?

@sepidehMS @krwq can you please help here?

@michael-x your repro description is a bit confusing for me. It would be best to pick the simplest one (new project) and just describe steps "1-5" how to get into the bad state. Mentioning that 4.6.2 SDK is the only difference between machines where it does/does not work (assuming I understood it correctly).

A simpler set of steps to reproduce:

  1. On machine A: Create a new .NET 4.6 Class Library project in Visual Studio 2015
  2. On machine B: Build using MSBuild 14 --> Works
  3. On machine A: Add NuGet package System.Text.Encoding.CodePages 4.3.0
  4. On machine B: Build using MSBuild 14 --> Works
  5. On machine A: Add NuGet package System.Xml.ReaderWriter 4.3.0
  6. On machine B: Build using MSBuild 14 --> Error

CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\Source\Test\ClassLibrary2\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\Facades\System.Xml.ReaderWriter.dll'. Remove one of the duplicate references.

Machine A has got Visual Studio 2015 installed, machine B has got the .NET Framework 4.6.2 SDK installed, no Visual Studio (build machine).

@michael-x do you also get build errors on Machine A on Step 5?
@ericstj I'm wondering if you know about some issues similar to this? Is it possible that 4.6.2 SDK is in some way different?

@krwq no, I don't get any build errors on machine A.

I've noticed that System.Text.Encoding.CodePages.dll seems to be portable and that there is a folder

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable

on machine A, but not on machine B. Could that be related? (I've tried installing "Microsoft .NET Portable Library Reference Assemblies 4.6" on machine B, but that didn't help.)

I was having the same problem with the same package. Building on my machine (VS 2015 Update 3) but failing on my build server (Build Tools 2015).

Fixed when I updated my build server to use the Build Tools 2015 Update 3.

@fabiano I just installed Microsoft Build Tools 2015 Update 3 and it looks like it did the trick. Thanks for your help!

The solution provided by @fabiano is working.

Thank you @fabiano!

If you'd like a smaller fix you can just update the NuGet extension. Our packages depend on NuGet 3.4.3 or later, but unfortunately we cannot pre-req that version in the packages, because we also need them to work in VS2013 where we need NuGet 2.12 or later.

This is a side-effect of NuGet not updating older VS versions with NuGet 3, but instead simultaneously updating NuGet 2.x and NuGet 3.x without providing a way for us to independent pre-req them.

@ericstj if you are referring to the NuGet extension for Visual Studio, then you are missing the point: it's the build on the machine that does not have Visual Studio installed that fails. Updating MSBuild Tools 2015 to Update 3 works for whatever magical reason. (I guess the key sentence in the release notes is "We've improved support for Portable class libraries targeting the .NET Platform Standard", but I'm not sure about that.)

I see, indeed I did miss the point. That does make sense. I believe a fix in Roslyn removed this check, but it would have been in for a long time. Perhaps Update 3 caused you to start using csc from buildtools (roslyn) instead of the old native csc (fx directory). The root issue still exists, MSBuild adds facades that are already provided by NuGet packages. This is being tracked with https://github.com/Microsoft/msbuild/issues/1345.

I would have thought that we are already using Roslyn since we are using compiler features like Interpolated Strings and Null-conditional Operators which to my knowledge are only implemented in Roslyn. Whether the issue that you've mentioned applies here I cannot tell.

I was seeing this issue also in projects that weren't using the Microsoft.CodeDom.Providers.DotNetCompilerPlatform in Azure (i.e. class libraries & console apps). By adding this package to these projects, the props\targets were updated and this issue was resolved. Note that this issue existed in Microsoft.Net.Compilers v1.0.0, so you'll need to latest (currently v1.3.2) if you see this issue & you have these packages in your project.

See https://github.com/projectkudu/kudu/issues/2336 for more info

What is the recommendation to make this work on Azure. Everything works fine on my computer but on Azure, it gives me this error.

I'm getting the Multiple Assemblies with Equivalent Identity

System.Xml.ReaderWriter is included as part of NetStandard.Library's nuget package and another package requires a nuget reference to System.Xml.ReaderWriter assembly version 4.3.0.

This blows up the build (I'm trying to deploy from github) with:

CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\home\site\repository\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll' and 'D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.1\Facades\System.Xml.ReaderWriter.dll'. Remove one of the duplicate references. [D:\home\site\repository\xxxxxxxxxx.Web\xxxxxxxxxxx.Web.csproj]

Has there many any resolution on this?? works fine locally and on other hosting but blows up on Azure..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chunseoklee picture chunseoklee  路  3Comments

noahfalk picture noahfalk  路  3Comments

bencz picture bencz  路  3Comments

btecu picture btecu  路  3Comments

jchannon picture jchannon  路  3Comments