Bug 34226 - System.Diagnostics.Tracing causes duplicate reference error (CS1703)
Summary: System.Diagnostics.Tracing causes duplicate reference error (CS1703)
Status: RESOLVED FEATURE
Alias: None
Product: iOS
Classification: Xamarin
Component: MSBuild ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-09-24 00:03 UTC by Cody Beyer (MSFT)
Modified: 2015-10-15 00:15 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
TestCase (400.65 KB, application/zip)
2015-09-24 00:03 UTC, Cody Beyer (MSFT)
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Cody Beyer (MSFT) 2015-09-24 00:03:08 UTC
Created attachment 13046 [details]
TestCase

### Description

Adding a reference to System.Diagnostic.Tracing from a NuGet package will cause a duplicate reference error. 

### Error

>/Users/derek/Documents/AppNamePath/Code/AppName/App_IOS/CSC: Error CS1703: An assembly >`System.Diagnostics.Tracing' with the same identity has already been imported. Consider removing one of the references (CS1703)

### Regression Status

This did not occur using C5SR3 release set

### Sample App

Attached

### Steps to Reproduce

1. Download and Open Sample
2. Build

### Expected Results 

App should build, as it did in C5SR3

### Actual Results

App fails with above error

### Versions

=== Xamarin Studio ===

Version 5.9.7 (build 9)
Installation UUID: 852fb169-eb98-4eeb-93fb-5f54eb55f790
Runtime:
	Mono 4.0.4 ((detached/cb6d6b2)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400040002

=== Apple Developer Tools ===

Xcode 7.0 (8227)
Build 7A220

=== Xamarin.iOS ===

Version: 9.0.1.20 (Business Edition)
Hash: d8e9592
Branch: master
Build date: 2015-09-18 23:22:05-0400

=== Xamarin.Android ===

Version: 5.1.6.7 (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.2.111 (Business Edition)

=== Build Information ===

Release ID: 509070009
Git revision: 31fa64709030b3edb971237780a452a4c69943c4
Build date: 2015-09-17 11:44:37-04
Xamarin addins: b105d33d8cd72911ff2cf3ee0b7715d37e5f19a6

=== Operating System ===

Mac OS X 10.10.5
Darwin BeyerStudiosMac.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 1 Marek Safar 2015-09-24 06:02:31 UTC
This is because iOS build adds references to all facade assemblies even if they are not used.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2015-09-24 08:04:05 UTC
@Marek, I'm not sure this is a bug in our MSBuild tasks, it looks like it's the ImplicitlyExpandDesignTimeFacades target which pulls in the facade System.Diagnostics.Tracing assembly:

>	Target ImplicitlyExpandDesignTimeFacades:
>	Task "Message"
>		Using task Message from Microsoft.Build.Tasks.Message, Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
>		Including /work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Collections.Concurrent.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Collections.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.ComponentModel.Annotations.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.ComponentModel.EventBasedAsync.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.ComponentModel.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Diagnostics.Contracts.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Diagnostics.Debug.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Diagnostics.Tools.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Diagnostics.Tracing.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Dynamic.Runtime.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Globalization.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.IO.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Linq.Expressions.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Linq.Parallel.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Linq.Queryable.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Linq.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Net.NetworkInformation.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Net.Primitives.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Net.Requests.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.ObjectModel.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Reflection.Extensions.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Reflection.Primitives.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Reflection.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Resources.ResourceManager.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Runtime.Extensions.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Runtime.InteropServices.WindowsRuntime.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Runtime.InteropServices.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Runtime.Numerics.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Runtime.Serialization.Json.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Runtime.Serialization.Primitives.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Runtime.Serialization.Xml.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Runtime.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Security.Principal.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.ServiceModel.Http.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.ServiceModel.Primitives.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.ServiceModel.Security.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Text.Encoding.Extensions.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Text.Encoding.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Text.RegularExpressions.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Threading.Tasks.Parallel.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Threading.Tasks.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Threading.Timer.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Threading.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Xml.ReaderWriter.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Xml.XDocument.dll;/work/maccore/xcode7.1/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Facades/System.Xml.XmlSerializer.dll
>	Done executing task "Message"
>	Done building target "ImplicitlyExpandDesignTimeFacades" in project "/Users/rolf/Downloads/TracingProblemsApp/TracingProblemsApp/TracingProblemsApp.csproj".

which seems to be defined here: https://github.com/mono/mono/blob/master/mcs/tools/xbuild/data/4.0/Microsoft.Common.targets#L914

Full build log: https://gist.github.com/rolfbjarne/f3c88fd215065dcdc2e4
Comment 3 Marek Safar 2015-09-24 10:03:17 UTC
@rolf, correct but the task has following inside

https://github.com/mono/mono/blob/master/mcs/tools/xbuild/data/4.0/Microsoft.Common.targets#L921

which should kick in and remove the duplicate.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2015-09-24 10:17:48 UTC
@Marek, won't that just remove exact duplicates (i.e. where the full path matches)? In this case there's another version that's referenced from a different path.

Could it be that this is where it should find the facade instead?

> Primary Reference System.Diagnostics.Tracing
> 	Reference System.Diagnostics.Tracing resolved to ../PCL/System.Diagnostics.Tracing.dll. CopyLocal = True
> 	Reference found at search path {HintPathFromItem}
> For searchpath {CandidateAssemblyFiles}
> Warning: {CandidateAssemblyFiles} not supported currently
> For searchpath {HintPathFromItem}
Comment 5 Marek Safar 2015-10-06 07:12:47 UTC
I looked into it again and there is several subtle issues involved but the error message CS1703 is correct because references are incompatible with each other. Simplest solution is to remove redundant PCL/System.Diagnostics.Tracing reference.

msbuild reports 

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.

which would help to diagnose issue but after that the compilation fails. Well, it does not actually always fail because it gives different result based on order of assembly references  due to bug in Microsoft C# compiler.
Comment 6 derekcrxamarin 2015-10-06 12:46:31 UTC
I disagree the the simplest solution is to remove the redundant PCL/System.Diagnostics.Tracing reference.  The problem here is that as of Xamarin.iOS 9 Xamarin is now including System.Diagnostic.Tracing which wasn't included before.  The System.Diagnostics.Tracing dll that Xamarin includes is incompatible with other Portable Class Libraries that we have been using.  Specifically the TPL Dataflow Nuget Package.

So the new inclusion of System.Tracing.Diagnostics has completely broken our code.  There needs to be a way to override libraries included by Xamarin because we can't be using Nuget packages at all if packages they depend are subject to Xamarin overriding them with incompatible versions.
Comment 7 Marek Safar 2015-10-08 08:40:00 UTC
Ok, let me repeat it again.

System.Diagnostics.Tracing.dll which is part of Xamarin is Facade assembly very much same one as you can find at C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades. It has no api it's just facade with forwarders which are supported with Xamarin.

You are referencing your different one so you get conflict. Please remove your version of System.Diagnostic.Tracing.dll. That should resolve the issue if you still get build error please attach full log?
Comment 8 Brendan Zagaeski (Xamarin Team, assistant) 2015-10-15 00:15:42 UTC
It turns out Comment 0 was missing some key additional context about the _reason_ for wanting to be able to include a "custom" copy of `System.Diagnostics.Tracing.dll`.

I have now posted a knowledge base article that discusses the particular use case related to the TPL Dataflow NuGet library in some depth:

https://kb.xamarin.com/customer/portal/articles/2161671-how-can-i-resolve-the-problems-related-to-system-diagnostics-tracing-for-the-microsoft-tpl-dataflow-nuget-package-

I included a couple "Questions & Answers" at the bottom of that article, in part based on this bug report. So hopefully that article will clear up any remaining questions on this topic.


As is hopefully clear from that article, the "core problem" that led to this bug is in fact Bug 27337. On the other hand, I think it is appropriate to leave this bug as "RESOLVED FEATURE" rather than marking it as a duplicate because this bug report does discuss a slightly different "secondary" question: "What problems can arise when building an app project that includes a reference to a Reference Assembly rather than (or in addition to) the corresponding Facade Assembly?"


Best,
Brendan
Xamarin Customer Support