// Load the assembly containing the method Assembly assembly = Assembly.LoadFrom("MyLibrary.dll"); // Get the type that contains the method Type type = assembly.GetType("MyLibrary.MyClass"); // Get the method ID for the method we want to call MethodInfo method = type.GetMethod("MyMethod", BindingFlags.NonPublic | BindingFlags.Instance); IntPtr methodID = method.MethodHandle.GetFunctionPointer(); // Call the method using a function pointer var function = (Func)Marshal.GetDelegateForFunctionPointer(methodID, typeof(Func )); int result = function.Invoke();
// Load the C++/CLI assembly containing the method Assembly assembly = Assembly.LoadFrom("MyCppCliLibrary.dll"); // Get the type that contains the method Type type = assembly.GetType("MyCppCliLibrary.MyClass"); // Get the method ID for the method we want to call MethodInfo method = type.GetMethod("MyMethod"); IntPtr methodID = method.MethodHandle.GetFunctionPointer(); // Call the method using a function pointer var function = (FuncIn this example, we load a C++/CLI assembly "MyCppCliLibrary.dll" and retrieve the method identifier for the public method "MyMethod" of the type "MyClass". We then convert the method ID to a function pointer and use it to invoke the method. The result of the method call is stored in the "result" variable. Package library: The GetMethodID method is part of the System.Reflection.Emit namespace in the System.Reflection.Emit.dll assembly. However, as shown in the examples above, it can be used with any assembly that contains a method with a given name and signature.)Marshal.GetDelegateForFunctionPointer(methodID, typeof(Func )); int result = function.Invoke();