swaroop.m

Hi All,

Need help with COM Interop.

I am trying to use interop and perform automation on a COM DLL.

In the process, i need to type cast an Object into a Class specified in COM DLL.

When i do the same in VB it works fine.

However when i typecast using C# , i get the following exception.

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type '<ClassName>'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type. Instances of this type cannot be cast to any other class; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

i get the same exception when i try to typecast to the interface.

Surprisingly, since i donot need to typecast in VB explicity, i am able to typecast.

Can you please help me nail this. Am i doing something wrong

Regards,
Swaroop

PS: am trying to perfrom automation of a COM Dll that comes with a tool called Extensis Portfolio.



Re: Visual C# General HELP Needed on COM Interop

greeneyes

I am struggling with the same issue. Did you ever resolve your problem I am writing an addin in C# that needs to communicate with a C++ com object.




Re: Visual C# General HELP Needed on COM Interop

swaroop.m

We have resolved the Issue by using VB.Net , using Option Strict Off;

The issue is with the Type Library provided by the Portfolio , Using C# since its Type-Safe or with VB.Net using Option strict on;

we will not be able to typecast some of the classes @ runtime.

hope this helps