You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to build an app that uses a third-party library with Native AOT in reflection free mode (IlcDisableReflection set to true).
Since that library uses the GetCustomAttribute method in a few places I turned on shimming for the attributes (Switch.System.Reflection.Disabled.DoNotThrowForAttributes set to true).
Since that shims GetCustomAttributes to return an empty array, I assumed that GetCustomAttribute would return null (as it normally calls GetCustomAttributes internally and returns the first matching attribute or null if not found).
However, instead I get a Reflection_Disabled exception as it seems to be calling the RuntimeTypeInfo.GetAttributeFlagsImpl method first. Here's the final part of the stacktrace:
at Internal.Reflection.RuntimeTypeInfo.GetAttributeFlagsImpl() + 0x33
at Internal.Reflection.Extensions.NonPortable.CustomAttributeSearcher`1.GetMatchingCustomAttributes(E, Type, Boolean, Boolean) + 0xa1
at Internal.Reflection.Extensions.NonPortable.CustomAttributeInheritanceRules.GetMatchingCustomAttributes(MemberInfo, Type, Boolean, Boolean) + 0x50
at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](MemberInfo) + 0x2d
Is there a particular reason why it would take this path?
Or is it the case that Native AOT needs a similar override to GetCustomAttributes for GetCustomAttribute that will return null when no reflection is used and the DoNotThrowForAttributes setting is turned on?
The text was updated successfully, but these errors were encountered:
This will be fixed when dotnet/runtime#67193 is fixed. We could introduce yet another shim for this (we can compute some of the AttributeFlags, but not all), but I think it will be better to look into dotnet/runtime#67193 at some point.
I'm trying to build an app that uses a third-party library with Native AOT in reflection free mode (
IlcDisableReflection
set totrue
).Since that library uses the
GetCustomAttribute
method in a few places I turned on shimming for the attributes (Switch.System.Reflection.Disabled.DoNotThrowForAttributes
set totrue
).Since that shims
GetCustomAttributes
to return an empty array, I assumed thatGetCustomAttribute
would returnnull
(as it normally callsGetCustomAttributes
internally and returns the first matching attribute ornull
if not found).However, instead I get a
Reflection_Disabled
exception as it seems to be calling theRuntimeTypeInfo.GetAttributeFlagsImpl
method first. Here's the final part of the stacktrace:Is there a particular reason why it would take this path?
Or is it the case that Native AOT needs a similar override to
GetCustomAttributes
forGetCustomAttribute
that will returnnull
when no reflection is used and theDoNotThrowForAttributes
setting is turned on?The text was updated successfully, but these errors were encountered: