HighTechTalks DotNet Forums  

Unable to cast COM object. . .

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Unable to cast COM object. . . in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Arghyle
 
Posts: n/a

Default Unable to cast COM object. . . - 06-22-2009 , 02:01 PM






Slowly losing my mind on this one. May be an extremely simple answer, but I
have no idea what it is.

I have a C++ COM object - let's say MyCalcs that implements IMyInterface.
And Let's say they exist in MyComponent.Dll.

Now I add a reference to MyComponent.Dll in VS2008 (C#). In my code I do:
"MYCOMPONENTLib.IMyInterface myInterface = new MYCOMPONENTLib.MyCalcs" and
then attempt to invoke "myInterface.DoStuff()".

When I attempt to invoke the method .DoStuff() I receive an error:
"Unable to cast COM object of type MYCOMPONENTLib.MyCalcs' to interface type
MYCOMPONENTLib.IMyInterface'. This operation failed because the
QueryInterface call on the COM component....failed due to the following
error: No such interface supported".

I also receive the same error message if I attempt to instantiate MyCalcs as
the object and invoke .DoStuff() directly on it.

Ok - that seems like a pretty straight forward error message. Except
MyCalcs *does* support IMyInterface. The object browser in VS2008 seems
fully aware of this. So does intellisense.

Also, if I step back into the COM world I can instantiate IMyInterface and
invoke the .DoStuff() method in Visual C++ using CoCreateInstance() and
QueryInterface(). So it seems to me that proves the COM component itself
functions just fine.

That seems to imply something is wrong with the way I'm interop'ing to the
component. But I have absolutely no idea what it could be. Anyone out there
ever seen something similar? Thanks!

Reply With Quote
  #2  
Old   
Arghyle
 
Posts: n/a

Default RE: Unable to cast COM object. . . - 06-22-2009 , 02:36 PM






Oh yeah, I forgot to add that if do the following:

MYCOMPONENTLib.MyCalcs calcObject = new MYCOMPONENTLib.MyCalcs;
Type myType = MyCalcs.GetType();
Type[] interfaces = myType.GetInterfaces();

I *do* see IMyInterface in the returned Type array.


"Arghyle" wrote:

Quote:
Slowly losing my mind on this one. May be an extremely simple answer, but I
have no idea what it is.

I have a C++ COM object - let's say MyCalcs that implements IMyInterface.
And Let's say they exist in MyComponent.Dll.

Now I add a reference to MyComponent.Dll in VS2008 (C#). In my code I do:
"MYCOMPONENTLib.IMyInterface myInterface = new MYCOMPONENTLib.MyCalcs" and
then attempt to invoke "myInterface.DoStuff()".

When I attempt to invoke the method .DoStuff() I receive an error:
"Unable to cast COM object of type MYCOMPONENTLib.MyCalcs' to interface type
MYCOMPONENTLib.IMyInterface'. This operation failed because the
QueryInterface call on the COM component....failed due to the following
error: No such interface supported".

I also receive the same error message if I attempt to instantiate MyCalcs as
the object and invoke .DoStuff() directly on it.

Ok - that seems like a pretty straight forward error message. Except
MyCalcs *does* support IMyInterface. The object browser in VS2008 seems
fully aware of this. So does intellisense.

Also, if I step back into the COM world I can instantiate IMyInterface and
invoke the .DoStuff() method in Visual C++ using CoCreateInstance() and
QueryInterface(). So it seems to me that proves the COM component itself
functions just fine.

That seems to imply something is wrong with the way I'm interop'ing to the
component. But I have absolutely no idea what it could be. Anyone out there
ever seen something similar? Thanks!

Reply With Quote
  #3  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: Unable to cast COM object. . . - 07-05-2009 , 11:33 PM



"Arghyle" <Arghyle (AT) discussions (DOT) microsoft.com> wrote

Quote:
Slowly losing my mind on this one. May be an extremely simple answer,
but I
have no idea what it is.

I have a C++ COM object - let's say MyCalcs that implements IMyInterface.
And Let's say they exist in MyComponent.Dll.

Now I add a reference to MyComponent.Dll in VS2008 (C#). In my code I do:
"MYCOMPONENTLib.IMyInterface myInterface = new MYCOMPONENTLib.MyCalcs" and
then attempt to invoke "myInterface.DoStuff()".

When I attempt to invoke the method .DoStuff() I receive an error:
"Unable to cast COM object of type MYCOMPONENTLib.MyCalcs' to interface
type
MYCOMPONENTLib.IMyInterface'. This operation failed because the
QueryInterface call on the COM component....failed due to the following
error: No such interface supported".
You wrote the C++ implementation, right?

Try setting a breakpoint in QueryInterface. Does it ever get called, or is
..NET calling QI on some wrapper object?



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4219 (20090705) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.