Bug 21147 - I can't use Xamarin.Auth together with Azure Mobile Services, getting duplicate managed type found.
Summary: I can't use Xamarin.Auth together with Azure Mobile Services, getting duplica...
Status: RESOLVED DUPLICATE of bug 16826
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.14.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-07-07 09:35 UTC by Magnus Johansson
Modified: 2014-10-19 21:53 UTC (History)
5 users (show)

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

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 DUPLICATE of bug 16826

Description Magnus Johansson 2014-07-07 09:35:42 UTC
So I create a Forms solution, in my PCL project I add the NuGet Microsoft.WindowsAzure.Mobile.

When I run my Android project (which of course references the PCL project), I get:

[MonoDroid] UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: A Microsoft Azure Mobile Services assembly for the current platform was not found. Ensure that the current project references both Microsoft.WindowsAzure.Mobile and the following platform-specific assembly: Microsoft.WindowsAzure.Mobile.Ext.

Ok, fine, I add the Microsoft.WindowsAzure.Ext (by manually Edit References->Browse to the ..packages..Microsoft.WindowsAzure.Mobile.Ext assembly and add it) to my Android project, but then I get:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Xamarin.Auth.AndroidAccountStore/SecretAccount, Xamarin.Auth.Android, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Xamarin.Auth.AndroidAccountStore/SecretAccount, Microsoft.WindowsAzure.Mobile.Ext, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' (MyApp.Android)

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Xamarin.Auth.FormAuthenticatorActivity, Xamarin.Auth.Android, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Xamarin.Auth.FormAuthenticatorActivity, Microsoft.WindowsAzure.Mobile.Ext, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' (MyApp.Android)

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Xamarin.Auth.FormAuthenticatorActivity/State, Xamarin.Auth.Android, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Xamarin.Auth.FormAuthenticatorActivity/State, Microsoft.WindowsAzure.Mobile.Ext, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' (MyApp.Android)

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Xamarin.Auth.WebAuthenticatorActivity, Xamarin.Auth.Android, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Xamarin.Auth.WebAuthenticatorActivity, Microsoft.WindowsAzure.Mobile.Ext, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' (MyApp.Android)

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Xamarin.Auth.WebAuthenticatorActivity/State, Xamarin.Auth.Android, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Xamarin.Auth.WebAuthenticatorActivity/State, Microsoft.WindowsAzure.Mobile.Ext, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' (MyApp.Android)

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Xamarin.Auth.WebAuthenticatorActivity/Client, Xamarin.Auth.Android, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Xamarin.Auth.WebAuthenticatorActivity/Client, Microsoft.WindowsAzure.Mobile.Ext, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' (MyApp.Android)
Comment 1 Udham Singh 2014-07-07 11:20:50 UTC
We have tried to reproduce this issue but not able to reproduce this. To reproduce this issue we have followed the steps mentioned below : 

1. Create a Forms application via File->New->Solution->Mobile Apps->Blank App(Xamarin.Forms Portable).
2. Add NuGet package "Microsoft.WindowsAzure.Mobile" in PCL progect via right click on PCL ->Add->Add Packages...
3. Set android application as startup project and deploy this on device.

Screencast : http://screencast.com/t/3o272Qu6mX8l

Please let us know if we missed anything.

Environment Info :

=== Xamarin Studio ===

Version 5.1 (build 479)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.4.0 ((no/954ed3c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000214

=== Xamarin.Android ===

Version: 4.14.0 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: 7.2.5.4 (Business Edition)
Hash: e7f4f92
Branch: 
Build date: 2014-06-18 02:37:27-0400

=== Build Information ===

Release ID: 501000479
Git revision: e5a428cec75d4cc7e6e3ccd8192a3660d013e7dc
Build date: 2014-06-26 09:28:17-04
Xamarin addins: 190d93e026e17280e75a3680ef38f2630b9228d3

=== Operating System ===

Mac OS X 10.9.2
Darwin MacMini.local 13.1.0 Darwin Kernel Version 13.1.0
    Thu Jan 16 19:40:37 PST 2014
    root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64
Comment 2 Magnus Johansson 2014-07-07 11:27:43 UTC
Yes, you are missing the Xamarin.Auth component on the android project.
Comment 3 Magnus Johansson 2014-07-07 11:30:43 UTC
..at least based on your description. I can't watch your screencast since it requires old non-mobile friendly techniques (Adobe Flash)...
Comment 5 Udham Singh 2014-07-08 07:22:13 UTC
Thanks Magnus,

I have again tried to reproduce this issue but not able to reproduce this. To
reproduce this issue I have followed the steps mentioned below : 

1. Create a Forms application via File->New->Solution->Mobile Apps->Blank
App(Xamarin.Forms Portable).
2. Add NuGet package "Microsoft.WindowsAzure.Mobile" in PCL project via right
click on PCL ->Add->Add Packages...
3. Add NuGet package "Xamarin.Auth" in android project via right click on android project ->Add->Add Packages...
4. Set android application as startup project and deploy this on device.

Screencast : http://screencast.com/t/9Tf2FGMjQ

Could you please let me know if I need to follow any specific steps to reproduce this issue and also provide your complete build info via Xamarin Studio -> About Xamarin Studio.
Comment 6 Paul Batum 2014-07-08 13:37:00 UTC
Hi Udham,

There seems to be a problem with the Xamarin.Auth NuGet package, because it does not seem to add a reference to the project. Try using the Xamarin.Auth component instead and you should see the failure.

For your reference, the Mobile Services SDK uses Xamarin.Auth internally which is why the duplicate types are found. 

Paul
Comment 7 Flavius Demian 2014-07-15 17:14:00 UTC
I hope this will be solved soon.
Comment 8 Flavius Demian 2014-07-15 17:23:06 UTC
I have manage to find a workaround. Create a Portable Class Library in which you add the nugget version of mobile services. In this way you can make a wrapper over the existing mobile services from the pcl. This clearly works and it the best solution till the bug is fixed.
Comment 9 Paul Batum 2014-08-11 23:07:12 UTC
Udham,

Did you try this again based on the instructions in my last comment?

Thanks,

Paul
Comment 10 Udham Singh 2014-08-13 07:04:06 UTC
Hi Paul,

We have tried to reproduce this  issue by following your instructions mentioned in comment 6 but still we are not able to reproduce the issue.

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

Application Output : https://gist.github.com/Udham1/ef26c9ac013383389913

We have tried to reproduce this issue on latest stable xamarin builds and for us this is working fine. Could you please try this with the latest stable xamarin builds and let us know if you are still getting this issue.

Environment Info : 

=== Xamarin Studio ===

Version 5.2.1 (build 1)
Installation UUID: 952292e8-1484-4c56-b664-6ff701bef591
Runtime:
	Mono 3.6.0 ((no/f540f8a)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 306000039

=== Xamarin.Android ===

Version: 4.14.0 (Business Edition)
Android SDK: /Users/xamarin76/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.Mac ===

Version: 1.10.0.4 (Business Edition)

=== Xamarin.iOS ===

Version: 7.2.6.28 (Business Edition)
Hash: 606f31a
Branch: 
Build date: 2014-08-01 15:27:48-0400

=== Build Information ===

Release ID: 502010001
Git revision: d06832ce9807d6be24aca225457e8b37c7669f6f
Build date: 2014-08-07 12:10:47-04
Xamarin addins: 1de032531be4cecf2f39dbee3b87aac78204058c

=== Operating System ===

Mac OS X 10.9.3
Darwin Xamarin76s-Mac-mini.local 13.2.0 Darwin Kernel Version 13.2.0
    Thu Apr 17 23:03:13 PDT 2014
    root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
Comment 11 Chintan 2014-08-13 08:23:59 UTC
Hi Udham,

It happens when linker behavior is set to either "Don't link" or "Link SDK assemblies only". Works fine when it's set to "Link all assemblies".

Regards,
Chintan.
Comment 12 Jonathan Pryor 2014-08-13 10:33:35 UTC
This error in Comment #0

> Error: Duplicate managed type found! Mappings between managed types and Java types must be unique.
> First Type: 'Xamarin.Auth.AndroidAccountStore/SecretAccount, Xamarin.Auth.Android, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null';
> Second Type: 'Xamarin.Auth.AndroidAccountStore/SecretAccount, Microsoft.WindowsAzure.Mobile.Ext, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Is a variation on Bug #16826: two different assemblies both define a type with the same namespace and same name ('Xamarin.Auth.AndroidAccountStore/SecretAccount'), which results in Xamarin.Android attempting to generate an identically named ACW for each of them, which isn't currently supported.

Which raises a question: why is the Xamarin.Auth.AndroidAccountStore/SecretAccount type defined in both Xamarin.Auth.Android.dll and Microsoft.WindowsAzure.Mobile.Ext.dll? If possible, Don't Do That™.

See also: https://bugzilla.xamarin.com/show_bug.cgi?id=15205#c1

*** This bug has been marked as a duplicate of bug 16826 ***
Comment 13 Chintan 2014-08-13 13:00:36 UTC
Ok, I understand this.

So, if both are needed in project then we need to modify source of any of these components, rebuild it and then use in our project.

Also, as I mentioned earlier "Link all assemblies" solved the problem. Is there any drawback using it over "Link SDK assemblies only"?

Thanks and Regards,
Chintan.
Comment 14 Jonathan Pryor 2014-08-13 13:30:22 UTC
> Is there any drawback using [Link All Assemblies] over "Link SDK assemblies only"?

Link All Assemblies tends to get less testing, and I often call it the "Please break my code" setting, because most user code is NOT written for an environment that supports linking, and thus if it's Reflection heavy it is very likely to break.

That said, if you test it and it works, then by all means please do so...
Comment 15 Chintan 2014-08-13 15:56:53 UTC
Ok, thanks for the explanation.
Comment 16 Paul Batum 2014-08-13 20:27:07 UTC
Hi Jonathan,

I'm a member of the Mobile Services team. Thanks for taking a look at this issue. We did not realize that it is not possible to have two types with the same full name from different assemblies loaded in a Xamarin app.

We are currently exploring other options. At a high level, the major problem that lead us to embedding Xamarin.Auth in the first place is that there is no strong name signed version of Xamarin.Auth on NuGet.

Thanks,

Paul
Comment 17 Paul Batum 2014-10-19 21:53:59 UTC
For anyone hitting this issue: upgrade to version 1.2.5 or later of the Mobile Services NuGet/Component. We've implemented a workaround that resolves the problem on both Xamarin.iOS and Xamarin.Android.