CloudyMarble
CloudyMarble

Reputation: 37566

How to reference a.Net 4.0 COM in a .Net 2.0 App

I had a Problem to use DotNet 4.0 DLL in a DotNet 2.0 Application, googling the Issue showed a single suitable solution: COM

Anyway i'm trying to do that now but i keep getting the following Error when i add the reference in my application (the reference is tlb):

The ActiveX type library 'MyLib.tlb' was exported from a .NET assembly and cannot be added as a reference. please reference the Assembly directly.

Am i missing anything? its stated on a lot of websites that this option should work: Example1, Example2

On the other hand its stated on an old link of microsoft that this option is not possible "By Design"

Any Ideas? Hints?

Home i'm not confusing things.

Thank you.

Upvotes: 0

Views: 464

Answers (1)

Yahia
Yahia

Reputation: 70369

Because it would lead to loading the .NET4 runtime in a process where the .NET2 runtime is already loaded - this is not possible by design! Support for mixing .NET versions in one process was introduced in .NET 4 .

IF you really need to make this work:

  • make a native out-of-process COM server which uses that .NET4 DLL
  • then use that server from your .NET2 process (NOT the .NET4 DLL directly !)

REMARK - after seeing your comment about EF4:

I strongly recommend to convert your .NET2 application to .NET 4 - anything else will be a real maintainance nightmare!

Upvotes: 3

Related Questions