-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Open
Labels
area-VM-reflection-monoReflection issues specific to MonoVMReflection issues specific to MonoVM
Milestone
Description
CustomAttributeTypedArgument.Value
is documented to return ReadOnlyCollection<CustomAttributeTypedArgument>
for arrays: https://learn.microsoft.com/en-us/dotnet/api/system.reflection.customattributetypedargument.value?view=net-9.0#remarks
For example, this is a standalone program which throws an InvalidCastException on Mono due this bug:
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
var attr = typeof(C).CustomAttributes.Single(d => d.AttributeType == typeof(A));
var arg = attr.ConstructorArguments.Single();
Console.WriteLine(arg.ToString());
class A : Attribute
{
public unsafe A(params B<delegate*<void>[]>.E[] a) { }
}
class B<T>
{
public enum E { }
}
[A(new B<delegate*<void>[]>.E())]
unsafe class C { }
Output on Mono due to this bug:
Unhandled Exception:
System.InvalidCastException: Specified cast is not valid.
at System.Reflection.CustomAttributeTypedArgument.ToString(Boolean typed)
at System.Reflection.CustomAttributeTypedArgument.ToString()
at Program.<Main>$(String[] args) in /home/venkad/extracts/Program.cs:line 9
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidCastException: Specified cast is not valid.
at System.Reflection.CustomAttributeTypedArgument.ToString(Boolean typed)
at System.Reflection.CustomAttributeTypedArgument.ToString()
at Program.<Main>$(String[] args) in /home/venkad/extracts/Program.cs:line 9
Expected output on CoreClr:
new B`1+E[[System.Void()[], System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][1] { 0 }
Output on Mono with the fix:
new B`1+E[[System.Void()[], System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][1] { 0 }
Copilot
Metadata
Metadata
Assignees
Labels
area-VM-reflection-monoReflection issues specific to MonoVMReflection issues specific to MonoVM