1

I have this large IDL that I am importing into a C# project.

Everything was fine until I had to use one interface that is not quite compatible with HRESULT -> COMException conversion (I can go into details here but that shouldn't be relevant).

Is it possible to add PreserveSig to that one type somehow? I would like to avoid the option of declaring all COM interfaces manually in C#. If there was a way to get a c# source file instead of assembly from tlbimp, that would suit me, but AFAIK there is no such way.

Any other options? Thanks.

Laurynas Biveinis
  • 10,547
  • 4
  • 53
  • 66

1 Answers1

2

You could decompile the interop library with Ildasm.exe, edit the declaration and put it back again with ilasm.exe. Use a sample C# declaration to know how to edit it.

Or you could just declare that one interface in C#. The name doesn't matter, only the GUID has to match. Open the interop library in Reflector and copy/paste the interface declaration into your C# code. Change the interface name and modify the method that causes the problem.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • So the second option means that, while I have to import TLB as a whole, I can create another C# interface for the offending type, and as long as GUID matches and the name doesn't match the autoimported one, everything's fine? – Laurynas Biveinis Oct 22 '10 at 09:53