简体   繁体   English

.net 4 运行 .net 2.0 程序集的应用程序

[英].net 4 Application running a .net 2.0 assembly

I am working on a .net 4 Application which needs to use a 3rd Party application in .net 2.0.我正在开发一个 .net 4 应用程序,它需要在 .net 2.0 中使用第 3 方应用程序。 Running it in .net 4 is causing some exceptions.在 .net 4 中运行它会导致一些异常。

Is it possible to force only the assembly be executed in .net 2?是否可以强制仅在 .net 2 中执行程序集?

Any ideas?有任何想法吗?

It's called mixed-mode, and you can do it by setting/changing some properties in app.config file, eg.:它被称为混合模式,您可以通过设置/更改 app.config 文件中的一些属性来实现,例如:

<startup useLegacyV2RuntimeActivationPolicy="true"> 
  <supportedRuntime version="v4.0"/> 
</startup>

Please try adding following XML to your configuration file.请尝试将以下 XML 添加到您的配置文件中。

<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727" />
  </startup>
</configuration>

Starting with .NET 4, you don't have to worry about compatibility issues at all!从 .NET 4 开始,您完全不必担心兼容性问题! Version 4 introduced a new feature called "In-Process Side-by-Side Execution", which essentially allows you to load multiple versions of the CLR into the same process.版本 4 引入了一个称为“进程内并行执行”的新功能,它本质上允许您将多个版本的 CLR 加载到同一个进程中。 In other words, since your main application is running on the 4.0 runtime, you can tell it to load the 2.0 runtime when you load the 2.0 CLR assembly.换句话说,由于您的主应用程序在 4.0 运行时上运行,您可以在加载 2.0 CLR 程序集时告诉它加载 2.0 运行时。 The 2.0 CLR assembly will use the 2.0 runtime, while your application will continue to use the 4.0 runtime. 2.0 CLR 程序集将使用 2.0 运行时,而您的应用程序将继续使用 4.0 运行时。

You can find more details from the links below:您可以从以下链接中找到更多详细信息:

When linking a .NET 2.0 Managed Assembly from a .NET 4.0 Application, which framework is used? 从 .NET 4.0 应用程序链接 .NET 2.0 托管程序集时,使用哪个框架?

https://msdn.microsoft.com/en-us/library/w4atty68(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/w4atty68(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM