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

Allow non-concrete classes when marshalling SafeHandle by-value #1052

Closed
elinor-fung opened this issue Apr 30, 2021 · 1 comment
Closed

Allow non-concrete classes when marshalling SafeHandle by-value #1052

elinor-fung opened this issue Apr 30, 2021 · 1 comment
Labels
area-DllImportGenerator Source Generated stubs for P/Invokes in C#

Comments

@elinor-fung
Copy link
Member

elinor-fung commented Apr 30, 2021

The source generator currently requires a non-abstract subclass of SafeHandle - even for by-value parameters. We require a concrete subclass to instantiate when handling out / ref, but shouldn't need it for by-value.

Declaring a P/Invoke using an abstract base class or SafeHandle itself is a common use case in runtime libraries - e.g:
Interop.Read.cs

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Read", SetLastError = true)]
internal static extern unsafe int Read(SafeHandle fd, byte* buffer, int count);

Interop.Properties.cs

[DllImport(Interop.Libraries.NCrypt, CharSet = CharSet.Unicode)]
internal static extern unsafe ErrorCode NCryptGetProperty(SafeNCryptHandle hObject, string pszProperty, [Out] void* pbOutput, int cbOutput, out int pcbResult, CngPropertyOptions dwFlags);

cc @AaronRobinsonMSFT @jkoritzinsky

@jkoritzinsky
Copy link
Member

Fixed by #1066

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-DllImportGenerator Source Generated stubs for P/Invokes in C#
Projects
None yet
Development

No branches or pull requests

2 participants