locked
COM object cast exception in .net RRS feed

  • Question

  • namespace x

    {

    [COMVisible(true)]

    public Netclass_A

    {

    }

    I have created an object of .net class(NetClass_A in assembly x.dll) in COM using CoCreateInstance() . now the com object i have accessed from my managed c++ class using a method has out parameter as IDispatch**, then I converted the IDispatch*pObject  to System::Object objDisp in Managed code

    Now I have another .net class in X.dll named as NetClass_B

    then call the following statement like from managed code,

    NetClass_B newObj= Activator.CreateInstance(guid);

    then calling  newObj.Initialize(10,objDisp);

    where in NetClassB , objDisp is typecasted to NetClass_A

    [COMVisible(true)]

    public Netclass_B

    {

    public void Initialize(int i , object obj)

    {

     object c=(NetClass_A)obj

    }

    }

    I got can not type cast System::_COMOBJEct to NetClass_A .

    what could be reason?

    Thursday, October 24, 2013 6:06 PM

All replies