Skip to content
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

Closed
Enigmatrix opened this issue May 30, 2020 · 4 comments
Closed

Generics return type with explicit layout in PInvoke #37198

Enigmatrix opened this issue May 30, 2020 · 4 comments

Comments

@Enigmatrix
Copy link

Enigmatrix commented May 30, 2020

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

@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label May 30, 2020
@Enigmatrix
Copy link
Author

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 Could not load type 'FfiResult'1 from assembly '...' because generic types cannot have explicit layout

@Enigmatrix Enigmatrix changed the title Generics return type in PInvoke Generics return type with explicit layout in PInvoke May 31, 2020
@AaronRobinsonMSFT AaronRobinsonMSFT added untriaged New issue has not been triaged by the area owner and removed untriaged New issue has not been triaged by the area owner labels Jun 8, 2020
@AaronRobinsonMSFT AaronRobinsonMSFT removed the untriaged New issue has not been triaged by the area owner label Jul 15, 2020
@AaronRobinsonMSFT AaronRobinsonMSFT modified the milestones: 5.0.0, 6.0.0 Jul 15, 2020
@jkoritzinsky
Copy link
Member

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.

@jkoritzinsky jkoritzinsky removed this from the 6.0.0 milestone Jun 21, 2021
@jkoritzinsky jkoritzinsky added the untriaged New issue has not been triaged by the area owner label Jun 21, 2021
@mangod9 mangod9 removed the untriaged New issue has not been triaged by the area owner label Jul 6, 2021
@mangod9 mangod9 added this to the Future milestone Jul 6, 2021
@AaronRobinsonMSFT
Copy link
Member

Closing as this is a duplicate of #43486.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants