-
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
C#9 Function pointer with generic return parameter crashes with BadImageFormat #46402
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
@fbrosseau Not at present. There is a small comment in the code that describes the issue actually. runtime/src/coreclr/vm/ceeload.cpp Lines 12877 to 12884 in 51f90ab
I did start on this support here but haven't gotten around to finishing it. |
This gets pretty complex with shared generic code. To fully support this, we would need to introduce a new generic dictionary type and tech JIT how to pass it around. |
I think supporting this for blittable types may be reasonable, but non-blittable types should stay unsupported. It should avoid the problems with the shared generic code as side-effect. |
Thanks for the replies. I thought unmanaged function pointers were limited to blittable types in the first place?? Or is this only for UnmanagedCallersOnly? I remember hitting a similar problem and working around it by using primitives only |
It is for UnmanagedCallersOnly. Calling unmanaged function pointers works for non-blittable types for historic reasons. It worked in managed C++ since forever, and so we could not easily take away when exposing function pointers in C#. It is best to use the unmanaged function pointers with blittable types only. |
Thanks for the details. I remember now that what I had to change at the time was ref/in/out blittables as function parameters with UnmanagedCallersOnly, so I changed to pointers. I don't want to derail my own thread, but is this something that could work, too? Or does ref/in/out require work by the marshaller at runtime, in native to managed transitions? I could create a separate issue if this is something that could realistically be supported. |
Yes, ref/in/out requires marshalling. It can be supported in future via source generators for interop. We do not have plans for improving runtime built-in support for marshalling of non-blittable types. |
Would this be considered a duplicate of #9136? |
@DaZombieKiller Yes, it does appear so. Closing in lieu of #9136. |
Description
Hello,
The following program crashes with BadImageFormatException (for simplicity, ignore the fact this simplified repro would nullref in the normal case, this bug happens before that)
Question
Is this an unsupported scenario the same way generic delegates have never been supported in PInvoke scenarios?
Configuration
5.0.101
x64
The text was updated successfully, but these errors were encountered: