14

A COM server is create and I registerd that.

When I am trying to add that COM server in a COM Client, I was not able to add, and following error is comming.

" A reference to 'COMTest' could not be added

The ActiveX type Library 'c\user\~\Debug\COMTest.tlb' was exported from a .NET assembly and can not added as a reference.

Add a reference to .NET instead "

can anybody tell me What is the mistake. I register the COM in both way, from VS also and also tried with command prompt.

PawanS
  • 7,033
  • 14
  • 43
  • 71

2 Answers2

9

This is a "why on Earth would you do that" message. Project + Add Reference, Browse tab, select the DLL, not the TLB. So you'll use the .NET class(es) directly instead of going through the COM interop twice.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 21
    IMO it's a **"why on earth doesn't this work"** situation. The .NET assembly can be used as COM Server (*"It's simple! Just add the ComVvisible attribute!"*), .NET apps can be COM clients (*"nwe and improved with the latest update"*). It should be a warning, not a full-stop. ----- Use case: I am replacing a native COM component with a .NET one, but the .NET client needs to remain compatible with both. – peterchen Jan 06 '11 at 15:00
  • 2
    .. That is true I can go for browse. But I am learning COM, and I am not able to understand the error!! I am registering the DLL as well as the tlb.... Even I gave snk key also. @peterchen.... ComVisible(true), I tried both, can explain me error. – PawanS Jan 07 '11 at 07:08
  • 1
    You should write the client code in a different language. Javascript, VBScript, VB6, something like that. Late binding is supported, VB.NET is a good language for that. Or the *dynamic* keyword in C# 4. – Hans Passant Jan 07 '11 at 07:35
  • 3
    @peterchen Another use case: the COM assembly is 32-bit and the referencing assembly is 64-bit. I *cannot* add a reference to it as a .NET assembly, because though that will succeed, it will not run. – shipr May 27 '15 at 21:16
2

I assume you referring .tlb. you should refer .dll,

And after registering it with regsvr32,You just need to find that dll in .net add reference in com tab. Look here for more.

Community
  • 1
  • 1
indiPy
  • 7,844
  • 3
  • 28
  • 39