I am attempting to invoke a method from a product COM API in my application.
I can successfully invoke the method with a single parameter using the code below but I need to pass some extra parameters (which are added as overloads).
Type _apiType = Type.GetTypeFromProgID("TheAPI.TheServer");
object _api = Activator.CreateInstance(_apiType);
_apiType.InvokeMember(
"Connect",
System.Reflection.BindingFlags.InvokeMethod,
null,
_api,
new object[] { 2 } // new object[] {2, "", "" }
);
I have tried adding additional parameters into the code I have above but I get the following error:
"Number of parameters specified does not match the expected number."
I can't seem to find any answer to this, I'm starting to think it's not possible. All the examples I have found suggest using Type.GetMethod() but this doesn't seem to work on COM Objects.
Number of parameters specified does not match the expected numberSo your method "Connect" doesn't expect 1 parameter.Connect_3)