简体   繁体   中英

.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. Running it in .net 4 is causing some exceptions.

Is it possible to force only the assembly be executed in .net 2?

Any ideas?

It's called mixed-mode, and you can do it by setting/changing some properties in app.config file, eg.:

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

Please try adding following XML to your configuration file.

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

Starting with .NET 4, you don't have to worry about compatibility issues at all! 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. 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. The 2.0 CLR assembly will use the 2.0 runtime, while your application will continue to use the 4.0 runtime.

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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