访问.net 4.0 dll中的.net2.0 dll
我想在我的 .Net4.0 dll 中加载 .NET 2.0 dll。我确实搜索了解决方案,并找到了“useLegacyV2RuntimeActivationPolicy”属性,我可以将其添加到我的 app.config 中,如以下网址所示: 混合模式程序集是针对版本“v1.1.4322”构建的
但是对我来说,问题是,就我而言,我尝试在 4.0 DLL 中使用 .net2.0 dll,而不是在 4.0 exe 中使用。原因是这个 4.0 dll 随后在 Excel 中用作自动化插件。
目前,当我从 Excel 访问 .NET 4.0 API(为某个功能加载 2.0 dll)时,我得到“混合模式 2.0 dll 无法在 4.0 运行时加载”,这是可以理解的,因为 COM 已加载 4.0 CLR,因此无法加载2.0 dll。
不知何故,我需要制作 4.0 DLL 来加载 2.0 运行时。我尝试将 app.config 添加到 4.0 dll,但我猜只有 .exe 默认情况下会读取 app.config 来加载 clr。 这是我在 4.0 dll 项目的 app.config 中的内容,但没有用。
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
</configuration>
如何解决此问题以使我的 .NET 4.0 DLL 能够使用 .NET 2.0 dll ?
谢谢, 玛尼
I want to load a .NET 2.0 dll in my .Net4.0 dll. I did search for the solution and found the 'useLegacyV2RuntimeActivationPolicy' attribute that I can add to my app.config as in this url : Mixed mode assembly is built against version 'v1.1.4322'
But the problem for me is that, in my case, I am trying to use the .net2.0 dll in my 4.0 DLL and not in an 4.0 exe. The reason is this 4.0 dll is then used in Excel as an automation add-in.
Currently, when I acccess my .NET 4.0 API (which loads the 2.0 dll for a feature ) from Excel, I get the 'mixed mode 2.0 dll cannot be loaded in 4.0 runtime' which is understandable since COM has loaded the 4.0 CLR and hence cannot load the 2.0 dll.
Somehow I need to make my 4.0 DLL to load the 2.0 runtime. I tried adding a app.config to the 4.0 dll but I guess only .exe reads the app.config by default to load the clr.
This is what I have in my app.config in the project of 4.0 dll but no use.
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
</configuration>
How do I solve this problem to enable my .NET 4.0 DLL to use .NET 2.0 dll ?
Thanks,
Mani
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
汉斯·帕桑特 (Hans Passant) 已经给出了答案,但他已发表评论。因此,在此单独回答。
该配置必须名为 excel.exe.config,并且应与 excel.exe 位于同一 Office 目录中,才能使此方案发挥作用。
The answer is already done by Hans Passant but he has posted as a comment. Hence, answering this separately in here.
The config has to be called excel.exe.config and should be in the same office directory as excel.exe for this scenario to work.