Bug 56317 - BTOUCH : error CS1704: An assembly with the same name has already been imported.
Summary: BTOUCH : error CS1704: An assembly with the same name has already been imported.
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: XI 10.10 (d15-2)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 15.3
Assignee: Alex Soto [MSFT]
Depends on:
Reported: 2017-05-12 21:15 UTC by Todd Diehl
Modified: 2017-05-26 12:58 UTC (History)
4 users (show)

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

Reproducible Project (3.23 MB, application/zip)
2017-05-12 21:15 UTC, Todd Diehl

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 Todd Diehl 2017-05-12 21:15:38 UTC
Created attachment 22147 [details]
Reproducible Project

BTOUCH fails when trying to build a bindings project that has a nuget reference that includes nested i18n resources with the same name.  Reproduced in the attached case.

NOTE: this appears to happen in VS for Mac, but not in Xamarin Studio for Mac.

=== Visual Studio Community 2017 for Mac ===

Version 7.0 (build 3146)
Installation UUID: cd88f51a-b105-40d8-ab8c-438427da2bf6
	Mono (2017-02/9667aa6) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500000100

=== NuGet ===


=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
SDK: /usr/local/share/dotnet/sdk/1.0.3/Sdks
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.0.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.5.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.3.2 (12175)
Build 8E2002

=== Xamarin.Mac ===

Version: (Visual Studio Community)

=== Xamarin.Android ===

Version: (Visual Studio Community)
Android SDK: /Users/todd.diehl/git/reader/beta/android-buildtools/android-sdk
	Supported Android versions:
		6.0 (API level 23)
		7.0 (API level 24)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 25.0.2

Java SDK: /usr
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Android Designer EPL code available here:

=== Xamarin.iOS ===

Version: (Visual Studio Community)
Hash: 3e5ac5ff
Branch: d15-2
Build date: 2017-05-05 18:11:38-0400

=== Xamarin Inspector ===

Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

=== Build Information ===

Release ID: 700003146
Git revision: 7553fda2e327d15807298d444007896e5b975dba
Build date: 2017-05-09 12:12:36-04
Xamarin addins: c3d580752be79fc902422f1d55d1cdc2d8b98799
Build lane: monodevelop-lion-d15-2

=== Operating System ===

Mac OS X 10.12.4
Darwin 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Paket 0.3
Comment 1 Timothy Risi 2017-05-15 17:04:19 UTC
Confirm that I see the same build error in VSfM, but it builds successfully in Xamarin Studio
Comment 2 Sebastien Pouliot 2017-05-15 18:09:00 UTC
@Tim were you using the same Mono (5.0 / csc) with XS ? or did you use mono 4.8 (mcs) ?
Comment 3 Timothy Risi 2017-05-15 18:10:17 UTC
I was on mono 5
Comment 4 Timothy Risi 2017-05-15 18:12:21 UTC
Though I just tried it with mono 5.2 (alpha channel) and it built successfully
Comment 5 Timothy Risi 2017-05-15 18:12:35 UTC
Sorry, built successfully in VSfM
Comment 6 Sebastien Pouliot 2017-05-15 18:29:06 UTC
@Alex this is a compiler error but we need to extract a compiler test case (without btouch) from this. Also check if there's some workaround that could be used until a fix is available, thanks!
Comment 7 Alex Soto [MSFT] 2017-05-16 21:32:28 UTC Comment hidden (obsolete)
Comment 8 Alex Soto [MSFT] 2017-05-16 21:41:08 UTC Comment hidden (obsolete)
Comment 9 Alex Soto [MSFT] 2017-05-16 22:51:15 UTC
Hello Todd, Sorry for the spam, it seems my last findings were incorrect, as a workaround, you can switch to use xbuild in Visual Studio for Mac preferences panel > Projects > Build > and uncheck Build with MSBuild instead of xbuild.

Seems that the issue lies in using MSBuild.

|         Results         |
|      | MSBuild | xbuild |
| VS4M |  Fails  |  Works |
| XS   |  Fails  |  Works |

Using MSBuild the BTouch Task under References collects a lot more of Dlls causing the CS1704 issue because mtouch is called with the `Libronix.Utility.resources.dll` that are not directly referenced by the binding project.

Btouch Tasks in msbuild and xbuild

Diagnostic xbuild logs: https://gist.github.com/dalexsoto/d65f84ea8b18ae7697f9a318a0662f5d

Diagnostic msbuild logs: https://gist.github.com/dalexsoto/4e9df2f1d3160fe7d1a555658280696e

I do not think this is a csc/mcs bug, mtouch is calling them with the provided arguments in the MSBuild's BTouch Task
Comment 10 Alex Soto [MSFT] 2017-05-17 22:23:16 UTC
Libronix.Utility.dll nor Libronix.Utility.Platform.dll reference any of the Libronix.Utility.resources.dll.

monodis --assemblyref /Users/Alex/Downloads/DuplicateNugetResourceTest/packages/Libronix.Utility.4.6.3/lib/xamarinios10/Libronix.Utility.dll
AssemblyRef Table
1: Version=
	Public Key:
0x00000000: 7C EC 85 D7 BE A7 79 8E
2: Version=
	Public Key:
0x00000000: 7C EC 85 D7 BE A7 79 8E
3: Version=
	Public Key:
0x00000000: 7C EC 85 D7 BE A7 79 8E
4: Version=
	Public Key:
0x00000000: 7C EC 85 D7 BE A7 79 8E
5: Version=
	Public Key:
0x00000000: 31 BF 38 56 AD 36 4E 35
6: Version=
	Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
7: Version=
	Public Key:
0x00000000: 84 E0 4F F9 CF B7 90 65

monodis --assemblyref /Users/Alex/Downloads/DuplicateNugetResourceTest/packages/Libronix.Utility.4.6.3/lib/xamarinios10/Libronix.Utility.Platform.dll
AssemblyRef Table
1: Version=
	Public Key:
0x00000000: 7C EC 85 D7 BE A7 79 8E
2: Version=
	Zero sized public key
Comment 11 Alex Soto [MSFT] 2017-05-17 23:04:28 UTC
After talking to Ankit, he pointed out that MSBuild is doing the right thing (finding satellite assemblies[1]) and that xbuild has a bug and it's not finding them (the xbuild bug won't be fixed).

The code[1] was introduced in maccore[2] to fix bug 22135 which Mtouch Task was not given satellite assemblies. 

[1]: https://github.com/xamarin/xamarin-macios/blob/master/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.ObjCBinding.CSharp.targets#L50

[2]: https://github.com/xamarin/maccore/commit/f0a86283491f0267f55080e4ece49bcd65ebebc1
Comment 12 Alex Soto [MSFT] 2017-05-18 02:02:51 UTC
PR: https://github.com/xamarin/xamarin-macios/pull/2105
Comment 13 Alex Soto [MSFT] 2017-05-22 00:52:34 UTC
PR merged in xamarin-macios/master @ e8aa3db9cb0b60e189bae3a4b85b8cfd126bcf77