This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 19391 - [Preserve(AllMembers=true)] not working when another attribute, [DataContract] is after it.
Summary: [Preserve(AllMembers=true)] not working when another attribute, [DataContract...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Tools and Addins (show other bugs)
Version: 4.13.x
Hardware: Macintosh Mac OS
: Highest normal
Target Milestone: 5.1
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2014-04-29 19:57 UTC by Jon Goldberger
Modified: 2015-04-20 06:10 UTC (History)
8 users (show)

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


Attachments
test project (457.63 KB, application/zip)
2014-04-29 19:57 UTC, Jon Goldberger
Details

Comment 1 Jon Goldberger 2014-04-29 19:59:22 UTC
I made a repro for this case, AndLibProjLinkerBug. 

To repro, build the solution as it is and click the button on the UI. You will get an exception when trying to run the Foo method.

Then go to AndLibProj.TestClass and uncomment lines 18 and 19, and comment lines 21 and 22 to reverse the order of the attributes.

Build and run and click the button. The Foo method runs and displays output in console.

My version info:

=== Xamarin Studio ===

Version 4.3.4 (build 0)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
Runtime:
	Mono 3.4.0 ((no/d4511ef)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000185

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.Android ===

Version: 4.12.3 (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	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)

=== Xamarin.Mac ===

Xamarin.Mac: 1.8.0.8

=== Xamarin.iOS ===

Version: 7.2.2.2 (Business Edition)
Hash: db4427f
Branch: 
Build date: 2014-04-22 12:49:14-0400

=== Build Information ===

Release ID: 403040000
Git revision: e2e118a56ebf05c9f15eafbf53379bdebded727c
Build date: 2014-03-12 15:39:07-04
Xamarin addins: 9f2eb9aed862e28ca23d2d2f34e22952087e6e4c

=== Operating System ===

Mac OS X 10.9.2
Darwin Jonathans-MacBook-Pro.local 13.1.0 Darwin Kernel Version 13.1.0
    Wed Apr  2 23:52:02 PDT 2014
    root:xnu-2422.92.1~2/RELEASE_X86_64 x86_64
Comment 4 Jonathan Pryor 2014-04-30 09:53:33 UTC
This appears to be a linker bug, because the [Preserve] attribute IS present in the linked assembly:

$ xbuild /t:SignAndroidPackage /p:Configuration=Release
$ MONO_PATH=/Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild-frameworks/MonoAndroid/v1.0:/Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild-frameworks/MonoAndroid/v4.4 \
monodis obj/Release/android/assets/AndLibProj.dll
...
.namespace AndLibProj
{
  .class public auto ansi beforefieldinit TestClass
        extends [mscorlib]System.Object
  {
    .custom instance void class [System.Runtime.Serialization]System.Runtime.Serialization.DataContractAttribute::'.ctor'() =  (01 00 00 00 ) // ....

    .custom instance void class [Mono.Android]Android.Runtime.PreserveAttribute::'.ctor'() =  (
                01 00 01 00 53 02 0A 41 6C 6C 4D 65 6D 62 65 72   // ....S..AllMember
                73 01                                           ) // s.

So TestClass is present, and [Preserve] is retained...but the only member actually retained is the default constructor; every other TestClass member has been removed.

The linker appears to be ignoring [Preserve(AllMembers=true)] in this case.
Comment 5 Sadik Ali 2014-04-30 11:00:17 UTC
I have checked this issue with test project attached in bug description and noticed the same behavior mentioned in comment 1. To reproduce this issue I have followed the steps mentioned in comment 1.

Screencast : http://screencast.com/t/YDgRyArB

Environment Info: 

=== Xamarin Studio ===

Version 4.2.3 (build 60)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.2.6 ((no/9b58377)
	GTK+ 2.24.23 theme: Raleigh
	GTK# (2.12.0.0)
	Package version: 302060000

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: 7.2.0.2 (Business Edition)
Hash: 58c3efa
Branch: 
Build date: 2014-10-03 18:02:26-0400

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.Android ===

Version: 4.12.3 (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)

=== Build Information ===

Release ID: 402030060
Git revision: 30c4afc300c2a39ec5300851357ce02e49dd217e
Build date: 2014-03-05 22:09:33+0000
Xamarin addins: f8a9589b57c2bfab2ccd73c880e7ad81e3ecf044

=== 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 6 Atsushi Eno 2014-07-30 14:28:40 UTC
Probably some code that iterates attributes and process [Preserve] should be more careful to process other attributes first.
Comment 7 Ben Dodson 2014-12-17 13:16:11 UTC
We got bit by this one again, cost us another few hours of debug time because I forgot about the issue.
Comment 8 Radek Doulik 2015-01-15 10:44:01 UTC
This bug is now fixed in master, commit ed02cde63dc6ce52483c8935cc0cbee9c787f147
Comment 9 Saurabh 2015-04-20 06:10:26 UTC
I have checked this Issue with latest builds. I am not getting ant exception after clicking on button from UI.

Application Output: https://gist.github.com/saurabh360/634d2ca705a46399616d
Build output: https://gist.github.com/saurabh360/06ca2bce69ff2e7d549b

=== Xamarin Studio ===

Version 5.9 (build 431)
Installation UUID: 2939b8b4-8977-42bd-82d6-100275ccd9cd
Runtime:
	Mono 4.0.0 ((detached/c8db1b0)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000144

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: 8.10.0.262 (Enterprise Edition)
Hash: 8a0e7bc
Branch: master
Build date: 2015-04-16 23:17:56-0400

=== Xamarin.Android ===

Version: 5.1.0.115 (Enterprise Edition)
Android SDK: /Users/360_macmini/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		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)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.0.262 (Enterprise Edition)

=== Build Information ===

Release ID: 509000431
Git revision: 7560726734fc7267de2fa9abed2509968deefaa8
Build date: 2015-04-17 19:25:48-04
Xamarin addins: 2e772c734ab3148054eae7bf8949f340fdeb5e5e

=== Operating System ===

Mac OS X 10.9.4
Darwin 360-MACMINIs-Mac-mini-2.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

Note You need to log in before you can comment on or make changes to this bug.