Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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 for Bug 60291 on
Developer Community or GitHub if you have new
information to add and do not yet see a matching new report.
If the latest results still closely match this report, you can use the
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
There is no option to force the linker to strip assembly if the 3rd party assembly is marked as [assembly: Preserve] in a Xamarin.Android assembly.
Tried to look through the linker + followed the options
Tried some hacky way too with no success:
<type fullname="*" preserve="nothing" required="false"/>
There are documentations about skip stripping specific things, but not otherwise. (not everything is documented, like how to keep nested generic classes)
Is there any way to achieve this?
Could you please add a project, which demonstrates the issue?
If that's 3rd party assembly, do you use LinkAll or LinkSDKOnly mode?
Created attachment 25412 [details]
example of preserved 3rd party
Link all, ofc.
The android tooling skips assemblies (with preserve) even if it's in LinkDescription not to skip.
In this example I try to shrink the Xamarin.Forms.Core.dll which will never happen because
605Kb 95% unused code
But cases like a nuget package with 3mb sized assembly marked as [assembly: Preserve] can hurt the app.
Still not sure if it's by design or a bug.
OK, now I see what you mean.
I think there's no way to do that in Xamarin.Android currently. You would have to remove the attribute by some other tool beforehand. (it would be probably easy to create such a tool with https://github.com/jbevain/cecil)
I guess the assembly which harms you is different than the Xamarin.Forms.Core as it is smaller than 3mb? You might try to contact the developers of the 3rd party assembly to find out why they used the Preserve attribute on the whole assembly.
So it's the Xamarin-Tooling's design and not a linker bug. I move the category because it's nothing to do with the linker then.
So the only option currently is manually modify the assembly or fork open source and build it myself.
Btw, if the linker removes some IL code I need, then I just define a tag in the xml descriptor. The biggest problem is if the assembly using lots of unwanted references...