-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Description
Failed output:
attr.Type: System.Runtime.InteropServices.PreserveSigAttribute
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at System.Reflection.CustomAttributeData.get_AttributeType () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/master/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Reflection/CustomAttributeData.cs:147
at MainClass.Main (System.String[] args) [0x00052] in <a90fc1674b9b42588ce3846543c65a1e>:0
Expected output:
attr.Type: System.Runtime.InteropServices.PreserveSigAttribute
attr.Type: System.Runtime.InteropServices.FieldOffsetAttribute
test case:
using System;
using System.Reflection;
using System.Runtime.InteropServices;
public class MainClass
{
public static void Main(string[] args)
{
var mi = typeof(MainClass).FindMembers(MemberTypes.Method, BindingFlags.Static | BindingFlags.Public, (m, criteria) => m.Name == "pinvoke", null);
foreach (CustomAttributeData data in ((MethodInfo)(mi[0])).CustomAttributes)
{
Console.WriteLine($"attr.Type: {data.AttributeType}");
}
}
[DllImport("libc")]
public static extern void pinvoke();
}
This is because of the CustomAttributeData being passed a null ctorInfo in the .ctor . And that seems to stem from this where it is trying to find a constructor for FieldOffsetAttribute that takes a string, but there seems to be only a .ctor taking an int. This came from 7454c2d .
This works fine with 2018-06.