Bug 9696 - Cannot bind library due to reference assembly already being used in an assembly.
Summary: Cannot bind library due to reference assembly already being used in an assembly.
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.4.x
Hardware: PC Mac OS
: --- major
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2013-01-21 12:20 UTC by Chris Hardy [MSFT]
Modified: 2013-01-21 16:24 UTC (History)
3 users (show)

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:

Description Chris Hardy [MSFT] 2013-01-21 12:20:54 UTC
When trying to bind a library that uses the same reference library in different jar files, causes the following error message:

Error CS1508: The resource identifier `__reference__myjarfile.jar' has already been used in this assembly (CS1508) (NameSpace)
Comment 3 Jonathan Pryor 2013-01-21 14:55:17 UTC
The problem is in Xamarin.Android.Bindings.targets, and a misunderstanding of <CreateItem/>:

>   <Target Name="AddEmbeddedReferenceJarsAsResources" DependsOnTargets="GenerateBindings">
>     <CreateItem Include="@(EmbeddedReferenceJar)"
>                 AdditionalMetadata="@(EmbeddedReferenceJar->'LogicalName=__reference__%(filename)%(extension)')">
>       <Output TaskParameter="Include" ItemName="EmbeddedResource" />
>     </CreateItem>
>   </Target>

The thing is, //CreateItem/@AdditionalMetadata contains additional Key=Value pairs to add to _each_ item in //CreateItem/@Include:


The result is that we update each value in @(EmbeddedReferenceJar) to all have the _last_ LogicalName=... setting in AdditionalMetadata, which happens to be the same value for everything.
Comment 4 Jonathan Pryor 2013-01-21 16:24:03 UTC
Fixed in master/79093581.

The workaround is to apply this patch to Xamarin.Android.Bindings.targets:

diff --git a/Xamarin.Android.Bindings.targets b/Xamarin.Android.Bindings.targets
index a779394..ac4a4bd 100644
--- a/Xamarin.Android.Bindings.targets
+++ b/Xamarin.Android.Bindings.targets
@@ -299,7 +299,7 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved.
   <Target Name="AddEmbeddedReferenceJarsAsResources" DependsOnTargets="GenerateBindings">
     <CreateItem Include="@(EmbeddedReferenceJar)"
-                AdditionalMetadata="@(EmbeddedReferenceJar->'LogicalName=__reference__%(filename)%(extension)')">
+                AdditionalMetadata="LogicalName=__reference__%(FileName)%(Extension)">
       <Output TaskParameter="Include" ItemName="EmbeddedResource" />