C#, System.__ComObject casting problem

S

stunt016

I have a program written in C# that handles communication between two
pieces of software. My problem only deals with getting a text array
from one program to this C# "Bridge". I can get the text array to the
bridge, where it is received as a system.object. My problem is casting
this system.object to a string array. The code I'm using is below.


System.Array advArgs = args as System.Array; //creates array for
parameters being received

object advCommands = advArgs.GetValue(2); //gets the 3rd parameter
which is the array from the external software, stores it in
advCommands.

GCListOrArray GCarray = new GCListOrArray(); //GCarray is new
GCListOrArray interface, this interface was written by the external
software develpoer for applications like this.

GCarray = (GCListOrArray)advCommands; //Convert advCommands to
GCListOrArray interface type

Basically, when I try to WriteLine, the compiler says that it cannot
cast System.__ComObject. I have tried everyway I know of casting it,
but had no luck. Any suggestions?

Thanks in advance.

Tyler
 
N

Nicholas Paldino [.NET/C# MVP]

Tyler,

I don't see why whis would work. Basically, you are trying to cast an
array type to this GCListOrArray type, which isn't possible, because the CLR
array types are just that, arrays of instances of that type, nothing else.

You need another way to convert the arry to a GCarray (really interface,
if it was defined in COM) class.
 
S

stunt016

I'm new to C#, I got thrown on this project. I'm not sure if
GCListOrArray is defined in COM. How would I check to see if it were
defined?

Thanks, Tyler
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top