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

[NativeAOT] Specific PInvoke not supported #241

Closed
ThomasFOG opened this issue Oct 17, 2020 · 2 comments
Closed

[NativeAOT] Specific PInvoke not supported #241

ThomasFOG opened this issue Oct 17, 2020 · 2 comments
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation

Comments

@ThomasFOG
Copy link

Hello there,

This is a follow up to #240, but not related to the same missing feature.

While implementing another third party SDK different from #240, we stumbled upon an unsupported type of PInvoke.

An example goes as follow:

[DllImport("somelibrary.dll", EntryPoint = "SomeEntryPoint")]
public static extern IntPtr SomeEntryPoint(
    [MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "SomeICustomMarshaler")]
    string arg1,
    HandleRef arg2
);

I'm assuming that it is related to custom marshalers.

Cheers!

@jkotas jkotas added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Oct 17, 2020
@MichalStrehovsky
Copy link
Member

This is #160 - I think we should be able to add support for this, but it's not very high up the priority list at this point.

You could work around by doing what the runtime would do manually - I think this should be equivalent:

public static IntPtr SomeEntryPoint(
    string arg1,
    HandleRef arg2
)
{
    ICustomMarshaler marshaler = SomeICustomMarshaler.GetInstance(null);
    IntPtr val = marshaler.MarshalManagedToNative(arg1);
    try
    {
        SomeEntryPoint(val, arg2);
    }
    finally
    {
        marshaler.CleanUpNativeData(val);
    }
}

[DllImport("somelibrary.dll", EntryPoint = "SomeEntryPoint")]
public static extern IntPtr SomeEntryPoint(
    IntPtr arg1,
    HandleRef arg2
);

@ThomasFOG
Copy link
Author

Ah! I should have checked the opened issues. Since it's a duplicate, I'm closing this one.

Thanks for pointing out that it's about the attribute, I'll be notifying the vendor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

No branches or pull requests

3 participants