Discussion:
Unable to cast COM object. . .
(too old to reply)
Arghyle
2009-06-22 19:01:03 UTC
Permalink
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!
Arghyle
2009-06-22 19:36:01 UTC
Permalink
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.
Post by Arghyle
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.
"MYCOMPONENTLib.IMyInterface myInterface = new MYCOMPONENTLib.MyCalcs" and
then attempt to invoke "myInterface.DoStuff()".
"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!
Ben Voigt [C++ MVP]
2009-07-06 04:33:01 UTC
Permalink
Post by Arghyle
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.
"MYCOMPONENTLib.IMyInterface myInterface = new MYCOMPONENTLib.MyCalcs" and
then attempt to invoke "myInterface.DoStuff()".
"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

Continue reading on narkive:
Loading...