Bug 27135 - Link all strips assembly attributes
Summary: Link all strips assembly attributes
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: XI 8.6.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-02-17 07:16 UTC by Luzanne
Modified: 2015-02-18 04:29 UTC (History)
3 users (show)

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

Sample (10.49 KB, application/octet-stream)
2015-02-17 07:16 UTC, Luzanne

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 Luzanne 2015-02-17 07:16:08 UTC
Created attachment 9875 [details]

See sample in the attachments.

Check AssemblyAttributesViewController.cs. The ViewDidLoad method is calling GetCustomAttributes(..) on the executing assembly.

When using Link all assemblies, the Assembly Attributes in the AssemblyInfo.cs are linked away, so this method return no information about the attributes in AssemblyInfo.cs. When I switch to Link SDK only, it returns all attributes defined in AssemblyInfo.cs

Expected result:
When using Link all assemblies, preserve all assembly attributes.

Version: (Business Edition)
Hash: dfb682f
Build date: 2015-01-08 13:39:32-0500
Comment 1 Udham Singh 2015-02-17 07:52:31 UTC
I have checked this issue with the help of sample app and instructions given in bug and able to reproduce the reported behaviour. Please refer the screencast : http://www.screencast.com/t/m4vjPfDBTF

Ide Log : https://gist.github.com/Udham1/e2bcb063099c733de7e4
System Log : https://gist.github.com/Udham1/8124eceaf799a9033832

Environment Info : 

=== Xamarin Studio ===

Version 5.7.2 (build 1)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
	Mono 3.12.0 ((detached/de2f33f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000076

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: d508c8e
Build date: 2015-02-15 22:17:46-0500

=== Build Information ===

Release ID: 507020001
Git revision: 103486e2547553077836a5ba20a973487b983830
Build date: 2015-02-13 11:56:36-05
Xamarin addins: 8dd5b934e86ef0595c022dd3930fd40e3376ab4c

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin76s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 2 Sebastien Pouliot 2015-02-17 08:33:10 UTC
Yes, this is by design. The linker remove several attributes that are not required by the runtime for execution. For projects with several assemblies that makes a significant size difference in the final bundle size.

When you use "Link all" this same logic is applied to every assembly (unless it's marked [assembly:Preserve] or if `--linkskip=XXX` is used). When you use "Link SDK" hen the logic is only applied to the assemblies shipped by Xamarin.iOS.

Note that, in general, things like the application version number is read from the bundle itself so it will match what Apple shows in the appstore.
Comment 3 Luzanne 2015-02-17 08:43:11 UTC
I'm using a shared AssemblyInfo across different platforms.

How can I preserve this attributes manually? --linkskip=mscorlib is not what I want. When I enable Link SDK only it adds more than 10MB to my app size, so using Linking All is necessary.
Comment 4 Sebastien Pouliot 2015-02-17 08:48:58 UTC
What assembly do you read the custom attributes from ?

Let's say it's `X.dll` then you can add `--linkskip=X` and this specific assembly (not the others) won't be modified by the managed linker (and will have all the attributes).

Using `--linkskip=mscorlib` would be one of the worse cases, but it's unlikely that it's those attributes you need (or "Link SDK" would not work for you, as it process mscorlib.dll).
Comment 5 Luzanne 2015-02-17 08:57:44 UTC
I read from Assembly.GetExecutingAssembly();

In the testcase is this 'AssemblyAttributes, Version=, Culture=neutral, PublicKeyToken=null'

Lets say, I want the sample app with 'Link all assemblies'. How can I preserve the attributes defined in the AssemblyInfo.cs so I can use them in the app?

I can use --linkskip=AssemblyAttributes, but the code in my application is not linked away when I don't use it...
Comment 6 Sebastien Pouliot 2015-02-17 15:07:36 UTC
If it's a shared AssemblyInfo then you should be able to use any assembly (pick the smallest one for the smallest impact on size) to gather the attributes.

> var assembly = typeof (type.from.the.small.assembly).Assembly.Get GetCustomAttributes (...);
Comment 7 Luzanne 2015-02-18 04:29:48 UTC
No, it's not a shared assembly. It is a shared AssemblyInfo.cs file across different projects, like iOS and Android with default information about the company, version number of the product.