Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

C#, System.__ComObject casting problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stunt016@gmail.com - 31 Aug 2006 16:52 GMT
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
Nicholas Paldino [.NET/C# MVP] - 31 Aug 2006 17:04 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>I have a program written in C# that handles communication between two
> pieces of software.  My problem only deals with getting a text array
[quoted text clipped - 23 lines]
>
> Tyler
stunt016@gmail.com - 31 Aug 2006 17:51 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.