Bug 29256

Summary: [XI 8.10] AOT "error: invalid symbol redefinition" caused by certain uses of generic types in Visual Basic PCLs
Product: iOS Reporter: Brendan Zagaeski (Xamarin Team, assistant) <brendan.zagaeski>
Component: GeneralAssignee: Bugzilla <bugzilla>
Severity: normal CC: mono-bugs+monotouch, rolf
Priority: ---    
Version: XI 8.10   
Target Milestone: 8.10   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Test case
Log files
Test case with the VB project already built

Description Brendan Zagaeski (Xamarin Team, assistant) 2015-04-20 18:02:58 UTC
Created attachment 10828 [details]
Test case

AOT "error: invalid symbol redefinition" caused by certain uses of generic types in Visual Basic PCLs

Regression status: REGRESSION between Xamarin.iOS (f7736a4) and Xamarin.iOS (c2c0012)

This might be related to bug 28961. Perhaps it's even a duplicate.

## Steps to reproduce

1. Ensure Visual Studio is paired with the Mac build host so that the remote build phase will run.

2. Attempt to build the "ClassicSingleViewIphone1" project from the attached test case in the "Release|iPhone" configuration in Visual Studio.

Note: If you compile the VB.NET PCL on Windows beforehand, then you can replace the VB.NET PCL project reference in "CSPortableLibrary2" with a `.dll` reference, and then you'll be able to reproduce the problem on OS X using `xbuild`. So, because this problem is not strictly limited to the XamarinVS extensions, I am filing it directly under "iOS" rather than "XamarinVS."

## Results on XI (c2c0012) (Bad)

The build fails during AOT compilation due to a "symbol redefinition" in one of the `.s` files.

### From `~/Library/Logs/Xamarin/MonoTouchVS/ClassicSingleViewIphone1_*.log`

> [20-Apr-2015 16:54:47] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
>   -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.2.sdk
>   -Qunused-arguments -miphoneos-version-min=7.0 -arch armv7 -c 
>   -o /Volumes/Cases/macuser/Library/Caches/Xamarin/mtbs/builds/ClassicSingleViewIphone1/0ebb50b60640f982b1bf022bd3eafa79/obj/iPhone/Release/mtouch-cache/CSPortableLibrary2.dll.armv7.o
>   -x assembler
>   /Volumes/Cases/macuser/Library/Caches/Xamarin/mtbs/builds/ClassicSingleViewIphone1/0ebb50b60640f982b1bf022bd3eafa79/obj/iPhone/Release/mtouch-cache/CSPortableLibrary2.dll.armv7.s
> [20-Apr-2015 16:54:47] /Volumes/Cases/macuser/Library/Caches/Xamarin/mtbs/builds/ClassicSingleViewIphone1/0ebb50b60640f982b1bf022bd3eafa79/obj/iPhone/Release/mtouch-cache/CSPortableLibrary2.dll.armv7.s:318:1: error: invalid symbol redefinition
> [20-Apr-2015 16:54:47] plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler:

### `CSPortableLibrary2.dll.armv7.s` does indeed contain multiple definitions for this symbol

> $ grep VBPortableLibrary1_ObjectProperty_add_ValueChanged /Volumes/Cases/macuser/Library/Caches/Xamarin/mtbs/builds/ClassicSingleViewIphone1/0ebb50b60640f982b1bf022bd3eafa79/obj/iPhone/Release/mtouch-cache/CSPortableLibrary2.dll.armv7.s
> 	.no_dead_strip plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler
> plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler:
> 	.no_dead_strip plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler
> plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler:
> 	.no_dead_strip plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler
> plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler:

There are 3 re-definitions of the symbol, one for each `ValueChanged += ...` line in `CSPortableLibrary2.Class1`.

## Results after replacing VB PCL with C# PCL

The test case includes a fairly literal line-by-line port of the VB PCL to C#. Switching "CSPortableLibrary2" to reference this C# project does seem to stop the problem, so the problem might be particular to the IL format of Visual Basic PCLs.

## Results on XI (f7736a4) (Good)

> $ grep VBPortableLibrary1_ObjectProperty_add_ValueChanged obj/iPhone/Release/mtouch-cache/CSPortableLibrary2.dll.armv7.s 
> 	.no_dead_strip plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler
> plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler:
> 	.no_dead_strip plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler_0
> plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler_0:
> 	.no_dead_strip plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler_1
> plt_VBPortableLibrary1_ObjectProperty_add_ValueChanged_VBPortableLibrary1_ObjectProperty_ValueChangedEventHandler_1:

Each re-definition has an extra number appended to the name, preventing any conflict.

## Version information

### Windows 8.1 64-bit, in VMWare Fusion 6.0.5 (2209127)

Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641

Xamarin   3.11.431.0 (3673cfb)
Xamarin.iOS (7741cc495ab0baf04ff0405d0604bc27f0ecae2e)

### OS X 10.9.5, MacBook Air

Xamarin.iOS, (Business Edition)
Hash: c2c0012
Branch: master
Build date: 2015-04-14 17:26:21-0400

Mono 4.0.0 (detached/d136b79)

Xcode 6.2 (6776), Build 6C131e
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-20 18:03:44 UTC
Created attachment 10829 [details]
Log files
Comment 3 Rolf Bjarne Kvinge [MSFT] 2015-04-21 04:38:37 UTC
@Brendan, can you attach a binary version of that VB PCL dll, so that I can to reproduce on Mac?
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-21 11:18:12 UTC
Created attachment 10841 [details]
Test case with the VB project already built

Sure thing. For convenience, I also made the other small adjustments needed to use the VB `.dll` rather than the VB project, and I reattached the whole test case.

The test case attached in this comment can now be built on either Mac or Windows to hit the error.

For example:
> $ xbuild /t:Build /p:Configuration=Release /p:Platform=iPhone ClassicSingleViewIphone1.sln

Note: the old `mdtool` tasks hit the same error as the new MSBuild tasks, so you can use whichever one you prefer.
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-21 11:19:49 UTC
Updating status to NEW per comment 4.
Comment 6 Rolf Bjarne Kvinge [MSFT] 2015-04-23 07:27:18 UTC
This has already been fixed in master.

*** This bug has been marked as a duplicate of bug 28961 ***