locked
get rid of __ComObject RRS feed

  • Question

  • What can I do to prevent .NET 2.0 from wrapping COM objects in System.__ComObject type? From what I read the class that I want to be wrapped with strongly typed RCW should implement IProvideClassInfo interface. And it does. Next I should create PIA and here I got some problems:

    >tlbimp SampleCOM.dll /primary /keyfile:sgKey.snk
    Microsoft (R) .NET Framework Type Library to Assembly Converter 3.5.21022.8
    Copyright (C) Microsoft Corporation.  All rights reserved.

    TlbImp : warning TI0000 : At least one of the arguments for 'ITypeInfo.RemoteGetTypeAttr' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
    TlbImp : warning TI0000 : At least one of the arguments for 'ITypeInfo.RemoteGetFuncDesc' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
    TlbImp : warning TI0000 : At least one of the arguments for 'ITypeInfo.RemoteGetVarDesc' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
    TlbImp : warning TI0000 : The type library importer could not convert the signature for the member 'tagARRAYDESC.rgbounds'.
    TlbImp : warning TI0000 : At least one of the arguments for 'ITypeComp.RemoteBind' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
    TlbImp : warning TI0000 : The type library importer could not convert the signature for the member 'tagFUNCDESC.lprgscode'.
    TlbImp : warning TI0000 : The type library importer could not convert the signature for the member 'tagFUNCDESC.lprgelemdescParam'.
    TlbImp : warning TI0000 : The type library importer could not convert the signature for the member 'tagPARAMDESC.pparamdescex'.
    TlbImp : warning TI0000 : At least one of the arguments for 'ITypeLib.RemoteGetLibAttr' cannot be marshaled by the runtime marshaler.  Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
    Type library imported to SampleCOMLib.dll

    And now a few questions:
    1. What can I do to prevent these warnings?
    2. Are they harmful?
    3. What should I do with generated PIA? Install it into GAC? With gacutil /i SampleCOMLib.dll?
    4. Then When I add a reference to my C# project should this PIA be visible in .NET tab or the same way as without PIA in COM tab?

    Friday, June 27, 2008 10:26 AM

Answers

  • This doesn't look good.  For one, you've got the wrong ITypeInfo interface, you need to one in System. Runtime. InteropServices. ComTypes.  You also should not expose the interface, it is not COM automation compatible and tlbimp justifiably complains.  Something else I don't understand is that you seem to run Tlbimp.exe on a type library that was generated by .NET.  You can't use a .NET generated COM visible component in a .NET app.  Generating a PIA is therefore pointless.  Not sure about any of this, I don't understand what you are doing.
    Hans Passant.
    • Marked as answer by Bruno Yu Tuesday, July 1, 2008 3:46 AM
    Friday, June 27, 2008 11:25 AM
  • Ok, it works now. I still don't know what these warnings mean and how to get rid of them but registering generated interop with regasm and gacutil /i solved my problem.
    • Marked as answer by Bruno Yu Tuesday, July 1, 2008 3:46 AM
    Monday, June 30, 2008 1:14 PM

All replies

  • This doesn't look good.  For one, you've got the wrong ITypeInfo interface, you need to one in System. Runtime. InteropServices. ComTypes.  You also should not expose the interface, it is not COM automation compatible and tlbimp justifiably complains.  Something else I don't understand is that you seem to run Tlbimp.exe on a type library that was generated by .NET.  You can't use a .NET generated COM visible component in a .NET app.  Generating a PIA is therefore pointless.  Not sure about any of this, I don't understand what you are doing.
    Hans Passant.
    • Marked as answer by Bruno Yu Tuesday, July 1, 2008 3:46 AM
    Friday, June 27, 2008 11:25 AM
  • SampleCOM.dll is written in plain C++ (without CLR). I want to use it in my c# application. But everytime the com object is created without using "new ElementClass()" contruct (it is taken from collection for example) it is wrapper by System.__ComObject and not ElementClass. Which is something that causes me many problems (for example when using it in data bound controls). I found out that there is Marshal.CreateWrapperOfType function which is able to convert __ComObject to ElementClass. This partly solves my problem. It would be even better if this function could be called by the interop itself. Is that possible?
    Friday, June 27, 2008 1:04 PM
  • Ok, it works now. I still don't know what these warnings mean and how to get rid of them but registering generated interop with regasm and gacutil /i solved my problem.
    • Marked as answer by Bruno Yu Tuesday, July 1, 2008 3:46 AM
    Monday, June 30, 2008 1:14 PM