Bug 42726 - [C7SR1, Windows only] "error CS0433: The type 'System.Drawing.SizeF' exists in both ... Mono.Android ... and ... System.Drawing.Primitives" and similar errors for other types in System.Drawing when Android app references a PCL project
Summary: [C7SR1, Windows only] "error CS0433: The type 'System.Drawing.SizeF' exists i...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 6.1.0 (C7)
Hardware: PC Windows
: --- critical
Target Milestone: 6.1.x (C7SR1)
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2016-07-21 23:01 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2016-08-03 15:18 UTC (History)
6 users (show)

Tags: BZRC7SR1B2_C7SR1B1, DefectEscapeReview_Done
Is this bug a regression?: Yes
Last known good build: XamarinVS 4.1.0.550 (84e8d93)


Attachments
Test case (9.58 KB, application/zip)
2016-07-21 23:01 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
Diagnostic MSBuild output (722.88 KB, text/plain)
2016-07-21 23:02 UTC, Brendan Zagaeski (Xamarin Team, assistant)
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:
VERIFIED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2016-07-21 23:01:50 UTC
Created attachment 16752 [details]
Test case

[C7SR1, Windows only] "The type 'System.Drawing.SizeF' exists in both ... Mono.Android ... and ... System.Drawing.Primitives" and similar errors for other types in System.Drawing when Android app references a PCL project


This might be the same issue as non-public Bug 42577, but since in this case it is showing up as a regression between C7SR0 and C7SR1, I am filing it separately to ensure it is addressed specifically for the C7SR1 release.  Thanks!




## Regression status: regression in Cycle 7 – Service Release 1, that seems to happen only on Windows?


### Windows

> BAD:  XamarinVS 4.1.2.7 (af04e96), Xamarin.Android 6.1.2.12 (e9815e9)
> GOOD: XamarinVS 4.1.1.3 (34a92cd), Xamarin.Android 6.1.1.1  (7db2aac)

### Mac

> GOOD: Xamarin.Android 6.1.1.1  (7db2aac379d451ca08ebf968a715f32c2341afaf) + Mono 4.4.2 (4dff7a3)
> GOOD: Xamarin.Android 6.1.2.16 (a88abb0985fd6225d82191304cb33feea5c0f518) + Mono 4.4.2 (4dff7a3)

## Steps followed to replicate

Attempt to build the attached test case in the "Debug" configuration.  For example:

msbuild /t:Build /p:Configuration="Debug" AndroidApp.sln


(The test case is just a template PCL and a template Android app that includes one extra line that instantiates a `System.Drawing.SizeF`.)




## BAD Results

The build fails due to conflicting definitions of types in `System.Drawing` between the `System.Drawing.Primitives` facade assembly and the `Mono.Android` assembly.


### Microsoft Build Tools 2013 (VS 2013)

> MainActivity.cs(5,31): error CS0433: The type 'System.Drawing.SizeF'
> exists in both 'c:\Program Files (x86)\Reference
> Assemblies\Microsoft\Framework\MonoAndroid\v5.0\Mono.Android.dll' and
> 'c:\Program Files (x86)\Reference
> Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Drawing.Primitives.dll'


### Microsoft Build Tools 2015 (VS 2015)

> MainActivity.cs(5,31): error CS0433: The type 'SizeF' exists in both
> 'Mono.Android, Version=0.0.0.0, Culture=neutral,
> PublicKeyToken=84e04ff9cfb79065' and 'System.Drawing.Primitives,
> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'




## GOOD Results

The build completes without error.
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2016-07-21 23:02:23 UTC
Created attachment 16753 [details]
Diagnostic MSBuild output
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2016-07-21 23:21:33 UTC
## Additional regression precision: the change was introduced between the previous Beta of C7SR1 and the most recent Beta

> BAD:  XamarinVS 4.1.2.7   (af04e96), Xamarin.Android 6.1.2.12 (e9815e9)
> GOOD: XamarinVS 4.1.0.550 (84e8d93), Xamarin.Android 6.1.0.72 (0b94250)
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2016-07-21 23:37:33 UTC
Based on my brief tests it seems the issue is specific to the Xamarin.Android build process and does not affect Xamarin.iOS (at least as of the current Beta versions).
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2016-07-21 23:43:58 UTC
In case it's helpful, `System.Drawing.Primitives.dll` is _not present_ in the Facades directory for Xamarin.iOS (in XamarinVS 4.1.2.7) on Windows or Xamarin.Android 6.1.2.12 on Mac:

- C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades

- /Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/xbuild-frameworks/MonoAndroid/v1.0/Facades/


But it _is_ present in the Facades folder for Xamarin.Android in XamarinVS 4.1.2.7:

- C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Drawing.Primitives.dll
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2016-07-22 00:18:42 UTC
## Temporary workaround based on Comment 4

Deleting the "extra" facade assembly [1] is indeed sufficient to stop the problem for this test case.

[1] C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Drawing.Primitives.dll
Comment 8 softlion 2016-07-22 08:07:52 UTC
Just fall into this bug. The workaround is working great. Ty!
Comment 10 Shruti 2016-07-25 07:17:03 UTC
***********************
Reproduce Status:
***********************
Mac:  I have build the attached project in Debug configuration using Xamarin.Android 6.1.2.12. and got build error:
"/Users/ixamarin78/Downloads/SystemDrawingFacadeConflict/AndroidApp1/MainActivity.cs(31,31): Error CS0433: The imported type `System.Drawing.SizeF' is defined multiple times (CS0433) (AndroidApp1)"

Windows:  Reproduced using  XamarinVS 4.1.2.7 :
On VS2013: Got build error "MainActivity.cs(5,31): error CS0433: The type 'System.Drawing.SizeF'
> exists in both 'c:\Program Files (x86)\Reference
> Assemblies\Microsoft\Framework\MonoAndroid\v5.0\Mono.Android.dll' and
> 'c:\Program Files (x86)\Reference
> Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Drawing.Primitives.dll'"

On VS2015: Got build error "MainActivity.cs(5,31): error CS0433: The type 'SizeF' exists in both
> 'Mono.Android, Version=0.0.0.0, Culture=neutral,
> PublicKeyToken=84e04ff9cfb79065' and 'System.Drawing.Primitives,
> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
"


***********************
Verified Status:
***********************

Mac: Attached test project is getting build successfully without any error with C7SR1 RC2 Xamarin.Android 6.1.2.20 

Windows: Attached test project is getting build successfully without any errors on VS 2013 and VS 2015 with C7SR1 RC2 Xamarin.VisualStudio_4.1.2.14 

Screencast: http://www.screencast.com/t/GijZD8JJa