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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
.. 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.
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.
@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.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.