-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
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 use calli with generic I receive a BadImageFormatException: 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.
.method public static !!T Invoke<T, T2>(native int func, !!T2 val) cil managed
{
ldarg.1
ldarg.0
calli unmanaged cdecl !!0(!!1)
ret
}
I am calling the above with T as long, and T2 as int.
.method public static int64 Invoke(native int func, int32 val) cil managed
{
ldarg.1
ldarg.0
calli unmanaged cdecl int64(int32)
ret
}
Metadata
Metadata
Assignees
Labels
Type
Projects
Status