-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generics return type with explicit layout in PInvoke #37198
Comments
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
This is an example of the struct I am returning from a PInvoke function. [StructLayout(LayoutKind.Sequential)]
public struct Error
{
public uint Code;
public IntPtr Cause;
}
[StructLayout(LayoutKind.Explicit)]
public struct FfiResult<T> where T: unmanaged
{
[FieldOffset(0)] public long Tag;
[FieldOffset(8)] public T Ok;
[FieldOffset(8)] public Error Error;
} This gives |
I think this falls more under type system/vm than interop since the runtime blocks loading a generic type with explicit layout, so we don't even get to the point of failing to use it in interop scenarios. |
Closing as this is a duplicate of #43486. |
Types with generic parameters and explicit layout should be able to be returned from PInvoke methods (assuming the type is blittable/unmanaged of course).
Currently on .NET Core 3.1, and it just silently fails
The text was updated successfully, but these errors were encountered: