如何引用a.Net 4.0 COM在.NET 2.0应用程序应用程序、Net、COM、NET

2023-09-07 10:30:33 作者:君临天下

我有一个问题,使用DOTNET的4.0 DLL在DOTNET的2.0应用程序,谷歌搜索的问题表现出了single合适的解决方案:COM

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

无论如何,我想现在要做到这一点,但我不断收到以下错误,当我添加引用我的应用程序(引用是 TLB ):

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):

该ActiveX类型库MyLib.tlb'是从一个.NET程序集出口   并且不能被添加作为参考。请直接引用了大会。

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

我缺少什么?它说了很多这个选项应该工作的网站: 例1 ,例2

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"

任何想法?提示?

首页我不是混乱的事情。

Home i'm not confusing things.

感谢你。

推荐答案

由于它会导致加载.NET4运行在该.NET2运行时已经加载的过程 - 这是不可能的设计! 支持混合.NET版本在一个过程中引入了.NET 4。

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:

请其采用了原生出来的进程COM服务器.NET4 DLL 然后使用该服务器从.NET2过程中(不是直接的.NET4 DLL!)

备注 - 看到有关EF4您的评论后:

REMARK - after seeing your comment about EF4:

我强烈建议你.NET2应用程序转换到.NET 4 - !什么都将是一个真正修的噩梦

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