passing class objects as parameters for Invoke Method using C#
What is the syntax for sending a class object as a parameter using the Invoke
method?
The Invoke
method call is causing an error:
"Object of type 'MSM_ns.MyParameterClass' cannot be converted to type 'MSM_ns.MyParameterClass'"
Parameters of basic data types work fine, but complex data types cause errors.
byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04 };
MyParameterClass myParams = new MyParametersClass("ABC", 123, 3.14159);
// attach to the dll
MethodInfo dllMethodInfo = Invoke.LoadDLL("MSM.dll", "MSM_ns", "MSMClass", "MSMMethod1");
// attach the parameters
object[] parameters = new object[2];
parameters[0] = data;
parameters[1] = myParams;
// call the DLL
bool result = (bool)dllMethodInfo.Invoke(null, parameters);
--------
public static bool MSMMethod1(ref byte[] 开发者_如何学运维dataToVerify, MyParameterClass myParams)
{
. . .
}
You're loading the same assembly twice, with two identical but incompatible types.
You need to only load the assembly once.
精彩评论