Bug 57825 - [linker] Type arguments to attributes that take System.Object aren't preserved
Summary: [linker] Type arguments to attributes that take System.Object aren't preserved
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools (show other bugs)
Version: master
Hardware: PC Mac OS
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2017-06-28 10:48 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2017-10-16 19:32 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: No
Last known good build:

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 for Bug 57825 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 original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Rolf Bjarne Kvinge [MSFT] 2017-06-28 10:48:49 UTC
Test case: https://github.com/rolfbjarne/TestApp/blob/linker-bug-with-object-attribute-arguments/AppDelegate.cs#L47-L77

Results in:

2017-06-28 12:43:17.209 unifiedtestapp[7529:4142715] Xamarin.iOS: Unable to locate assembly 'System.Net.Http' (culture: '')
2017-06-28 12:43:17.209 unifiedtestapp[7529:4142715] Xamarin.iOS: Unable to locate assembly 'System.Net.Http' (culture: '')
Thread started:  #2
2017-06-28 12:43:22.001 unifiedtestapp[7529:4142715] 
Unhandled Exception:
System.TypeLoadException: Could not load type System.Net.Http.HttpClientHandler, System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a while decoding custom attribute: (null)
  at (wrapper managed-to-native) System.MonoCustomAttrs:GetCustomAttributesInternal (System.Reflection.ICustomAttributeProvider,System.Type,bool)
  at System.MonoCustomAttrs.GetCustomAttributesBase (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inheritedOnly) [0x00013] in /work/maccore/15.3/xamarin-macios/external/mono/mcs/class/corlib/System/MonoCustomAttrs.cs:128 
  at System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) [0x00037] in /work/maccore/15.3/xamarin-macios/external/mono/mcs/class/corlib/System/MonoCustomAttrs.cs:158 
  at System.Reflection.MonoMethod.GetCustomAttributes (System.Type attributeType, System.Boolean inherit) [0x00000] in /work/maccore/15.3/xamarin-macios/external/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:393 
  at AppDelegate.Main (System.String[] args) [0x00001] in /Users/rolf/Projects/TestApp/AppDelegate.cs:62 

when run on device.

This happens because the linker does not preserve Type arguments to attributes if the parameter type is System.Object (as opposed to System.Type): https://github.com/mono/linker/blob/59dd9e97cb39eb54dc69e76758ab0f9ec232854e/linker/Mono.Linker.Steps/MarkStep.cs#L449
Comment 1 Zack Gramana 2017-10-16 19:32:06 UTC
Was just bitten hard by this issue. For what it's worth, I was able to work around it by moving my custom attribute parameter types from `object[]` to `string[]`.