-
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
Unmanaged calli not supported with generic arguments #9136
Comments
Unmanaged calli is not supported with generic arguments. It is the same underlying reasons why DllImport is not supported with generics. |
I see that this pull request allows to use blittable types. Is it applicable to |
Yes, the same rules should apply to calli. |
So it is expected in .NET Core 3.1, right? |
No, .NET Core 3.1 is "done" for a while. All features we have been working on for last several months are for .NET 5. |
Any plan to make it in .NET 7? |
I think this problem should be revisited, since function pointers can now be used in pure C# (unsafe unsafe TRet Invoke<TArg, TRet>(nint function, TArg arg)
{
var ptr = (delegate* unmanaged<TArg, TRet>)function;
return ptr(arg);
} |
Should we enable the unmanaged calli when the assembly has DisableRuntimeMarshallingAttribute? It should be much easier to implement and explain the behavior when the runtime marshalling is out of the picture. |
https://github.com/microsoft/CsWinRT can use this. cc @manodasanW |
That would definitely be an interesting proposition. I think CsWinRT might also need/want #55144 with the same restrictions if we can do that. This is definitely the easier side to implement though and would be useful on its own. |
I hit this while trying to use the below helper method to implement ComWrappers in AvaloniaUI/Avalonia#13924 public static T InvokeAndGet<T>(void* @this, int vtblSlot) where T : unmanaged
{
T ret;
int hr = ((delegate* unmanaged<void*, T*, int>)(*(*(void***)@this + vtblSlot)))(@this, &ret);
if (hr != 0)
Marshal.ThrowExceptionForHR(hr);
return ret;
} |
With pointer args like this, you can just cast to |
I am trying to write a cross platform library that interops with native code, and was planning on using raw IL and the
calli
instruction to call into my native functions, to allow me to at runtime select the native library to load. I have used this in the past, where I would create individual shim functions for every call, and this worked. However, I was thinking, and reading through the IL spec it seems like it should be allowed, to just build some generic template to handle this code for me. However, when attempting to usecalli
with generic I receive aBadImageFormatException: Bad element type in SizeOf
exception when the JIT attempts to compile the code. It seems like this should work, which makes it seem like a bug in the JIT. Below is both the generic code that seems like it should work, and also the same code without generics that does work.I am calling the above with T as long, and T2 as int.
The text was updated successfully, but these errors were encountered: