Trying to use GetFunctionPointerForDelegate
to pass a function pointer over interop, (C# -> C++). However, I am getting the exception: The specified Type must not be a generic type definition.
As far as I can tell I am not passing in a generic type definition, when inspecting the type of the delegate I saw the following:
I wrote a minimum example and observed the same behaviour, would appreciate any advice as to what I'm missing.
using System;
using System.Runtime.InteropServices;
public class MyTestClass
{
public void Foo()
{
Delegate del = new Func<int, int>(Bar);
IntPtr funcPtr = Marshal.GetFunctionPointerForDelegate(del);
}
public int Bar(int a)
{
return 0;
}
}
public class Program
{
public static void Main()
{
var mtc = new MyTestClass();
mtc.Foo();
}
}
The issue can be observed on dotnet fiddle: https://dotnetfiddle.net/8Aol9j