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)

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


Attachments

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[]`.

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