Mehi
Mehi

Reputation: 37

System.Reflection.TargetParameterCountException' occurred in System.Windows.Forms.dll

It seems weird to me. All definitions match but it seems there is a problem with invoking a function with input array<Object^>^ . Here is my brief code:

void WriteCOMPortPannel(array< String ^ >^ ){ \\ Do something};
delegate void WriteCOMPortDelegate(array< String ^ >^ );

array <String^ > ^COM_PORTS = this -> SerialPort ->GetPortNames();          
this->Invoke (gcnew WriteCOMPortDelegate(this, &MainForm::WriteCOMPortPannel), COM_PORTS);

In C# the solution is:

this->Invoke (MyDeligate , New Object() COM_PORTS);.

What about C++\CLI ? Is there any type mismatch ?

Upvotes: 0

Views: 458

Answers (1)

Medinoc
Medinoc

Reputation: 6608

I guess The C++/CLI Invoke mistakes your array< String^ >^ for the array< Object^ >^ it expects to hold a parameter list.

You should try wrapping your array< String^ >^ inside an array< Object^ >^.

array <String^ > ^COM_PORTS = this -> SerialPort ->GetPortNames();          
array <Object^ > ^parameters = gcnew array <Object^ >(1);
parameters[0] = COM_PORTS;
this->Invoke (gcnew WriteCOMPortDelegate(this, &MainForm::WriteCOMPortPannel), parameters);

Upvotes: 1

Related Questions