none
.NET and COM interop problem RRS feed

  • Question

  • I created a simple COM component, with a put/get method to operate on one field. I would use this COM component in my .NET codes, by using the interop wrapper. In .NET codes, the put/get method will become a property. Assigning value to the property should invoke the put method. However, I found that it will invoke the get method and will cause exceptions.

    Below is the COM interface:

    interface IMyData : IUnknown 
    {
      [propget, helpstring("property ForceActive")] HRESULT ForceActive([out, retval] VARIANT_BOOL *pVal);
      [propput, helpstring("property ForceActive")] HRESULT ForceActive([in] VARIANT_BOOL newVal);
    }

    Below is the codes of .NET to invoke the put method:

    //After fetch the interface
    myData.ForceActive = true;

    I used the MSIL Assembler to check the COM interop wrapper, and found the definition is correct, like
    .property bool ForceActive()
    {
      .custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( 01 00 1C 00 01 60 00 00 )                         // .....`..
      .set instance void AgtVsaDataLib.IDataVector::set_ForceActive(bool)
      .get instance bool AgtVsaDataLib.IDataVector::get_ForceActive()
    } // end of property IDataVector::ForceActive

    Do anybody here can help to point out if I've made any mistakes here? I was using VS2005 and .NET 2.0.

    Thanks.

    Henry Xing, Beijing, China
    Tuesday, July 8, 2008 1:04 AM

Answers

  • Smells like a classic COM versioning issue, the type library not matching the v-table.  One extra added method in the actual version of the COM component and you'd get what you see.
    Hans Passant.
    • Marked as answer by Henry Xing Thursday, July 10, 2008 12:55 AM
    Tuesday, July 8, 2008 1:38 AM
    Moderator