-
Notifications
You must be signed in to change notification settings - Fork 5k
The "PInvokeTableGenerator" task failed unexpectedly when using delegate*
in [DllImport]
#60802
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
Comments
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsDescriptionThis code results in an error: extern static void my_class_set_callback(nint obj, delegate* unmanaged<bool, nint, void> callback, nint state);
I tried
Reproduction Steps
Expected behaviorNo error. I am trying to replicate this code without the MyClass myInstance = new MyClass();
unsafe class MyClass
{
private nint handle;
public MyClass()
{
handle = my_class_new();
var callbackState = (IntPtr)1234;
my_class_set_callback(handle, OnCallbackProxy, callbackState);
my_class_set_value(handle, 10);
}
[DllImport("library")] extern static nint my_class_new();
[DllImport("library")] extern static void my_class_set_value(nint obj, int value);
[DllImport("library")] extern static void my_class_set_callback(nint obj, MyCallback callback, nint state);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void MyCallback([MarshalAs(UnmanagedType.I1)] bool is10x, nint state);
[MonoPInvokeCallback(typeof(MyCallback))]
static void OnCallback([MarshalAs(UnmanagedType.I1)] bool is10x, nint state)
{
Console.WriteLine($"Here! {is10x} and {state}");
}
static readonly MyCallback OnCallbackProxy = OnCallback;
}
[AttributeUsage(AttributeTargets.Method)]
internal sealed class MonoPInvokeCallbackAttribute : Attribute
{
public MonoPInvokeCallbackAttribute(Type type)
{
Type = type;
}
public Type Type { get; private set; }
} Actual behaviorError. Using this: MyClass myInstance = new MyClass();
unsafe class MyClass
{
private nint handle;
public MyClass()
{
handle = my_class_new();
var callbackState = (IntPtr)1234;
delegate* unmanaged<bool, nint, void> proxy = &OnCallbackUnmanagedOnly;
my_class_set_callback(handle, (void*)proxy, callbackState);
my_class_set_value(handle, 10);
}
[DllImport("library")] extern static nint my_class_new();
[DllImport("library")] extern static void my_class_set_value(nint obj, int value);
[DllImport("library")] extern static void my_class_set_callback(nint obj, void* callback, nint state);
//[DllImport("library")] extern static void my_class_set_callback(nint obj, delegate* unmanaged<bool, nint, void> callback, nint state);
[UnmanagedCallersOnly]
static void OnCallbackUnmanagedOnly(bool is10x, nint state)
{
Console.WriteLine($"Here! {is10x} and {state}");
}
} Regression?No response Known WorkaroundsUse the old Configuration
Other information
|
The pinvoke table generator can't handle unmanaged function pointers, because |
Thank you for sharing the code, which I can use in a test case. This is a dupe of #56145 . |
Description
This code results in an error:
I tried
void*
in there just in case it was something to do with thedelegate*
, but I now get a runtime error:Reproduction Steps
Expected behavior
No error. I am trying to replicate this code without the
MonoPInvokeCallbackAttribute
:Actual behavior
Error.
Using this:
Regression?
No response
Known Workarounds
Use the old
[MonoPInvokeCallback]
formatConfiguration
Other information
BlazorApp6.zip
The text was updated successfully, but these errors were encountered: