• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1005
  • Last Modified:

unable to cast the system.object[,] type contains system.array

i hv a com method which returns the object type system.object[,] contains list of users. when i am trying to form an array of this type i am getting the error as "cast is not valid ". The following is my code snippet.

I am calling a COM method in c# which returns the type system.object[,] contains list of all users. when i am trying to form an array of this type i am getting the errors as "cast is not valid".

The followin is my code,

try
                  {
                  
                        askLib.askQueryData objQueryData = new askLib.askQueryDataClass();
                        string tn = "sql2";
                        Object out1;
                        Object c="";
                        int i=0;
                        int j=25;
                        objQueryData.mf_GetAllUsers((Object)tn,(Object)c,(Object)i,(Object)j,out out1);

                        Console.WriteLine("output" + out1);
                        Object[,] procSection = (Object[,])out1;
                  }
                  catch(Exception excp)
                  {
                        MessageBox.Show (excp.ToString());
                  }
                  
Actually i want to print the username.

any help.

regards
sathish.
0
v_l_narasimhan
Asked:
v_l_narasimhan
  • 2
  • 2
  • 2
  • +2
1 Solution
 
cyberdevil67Commented:
Hi DrDamnit,

 Hmmm, I thought com objects always returned a collection:-)


Cheers!
0
 
CallandorCommented:
Did you try casting it as System.Object[,] instead of Object[,] ?
0
 
v_l_narasimhanAuthor Commented:
Hi

but i am forming the array using object[,] only.

my problem is casting the object type.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
cyberdevil67Commented:
Have you tried this as suggested

objQueryData.mf_GetAllUsers((System.Object)tn,(System.Object)c,(System.Object)i,(System.Object)j,out out1);

0
 
AgariciCommented:
may be obj1 is null?
if it was, you will certenly receive an 'invalid cast' error

try putting a breakpoint on the console.writeline line and examine your obj1 in your watch window
also you may try to see what opearations you can do on that object in the console window


hth,
A.
0
 
dunglaCommented:
Object out1;
objQueryData.mf_GetAllUsers((Object)tn,(Object)c,(Object)i,(Object)j,out out1);

Your our1 variable is an object type, then you can not cast to object[]. Make sure mf_GetAllUsers return object[].
It should be
object[] out1;
objQueryData.mf_GetAllUsers((Object)tn,(Object)c,(Object)i,(Object)j,out out1);
0
 
v_l_narasimhanAuthor Commented:
Hi

this method returns system.object[,]
0
 
dunglaCommented:
you mean mf_GetAllUsers will return object[]? so why do you need out parameter? just do something like that
Object[,] procSection = objQueryData.mf_GetAllUsers((Object)tn,(Object)c,(Object)i,(Object)j,out out1);
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now