Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which .net framework version will a library run in

Tags:

c#

.net

If i have a library which is compiled in .NET 4 and reference it from a .net 4.5 executable which version of the framework will operations defined in the library execute against?

I have a cli app which is built in .net 4.5 and references both .net 4 and .net 4.5 projects and im wondering if both will use the same version of the ADO.net components.

like image 219
Not loved Avatar asked Mar 29 '12 07:03

Not loved


People also ask

Can I use a .NET Framework library with .NET 6?

Yes, you can load . NET Framework assemblies into . NET Core 5 and 6.

Can .NET 5 use .NET Framework libraries?

NET Framework libraries aren't available for use with . NET 5+ (and . NET Core), such as app domains, remoting, and code access security (CAS).

Which version of .NET Framework should I use?

A cross-platform and open-source framework, . NET Core is best when developing applications on any platform. . NET Core is used for cloud applications or refactoring large enterprise applications into microservices. You should use .

Can I use .NET standard library in .NET Framework?

NET Standard 2.0. . NET Standard 2.0 is supported by all modern platforms and is the recommended way to support multiple platforms with one target.


1 Answers

They will both run in the same CLR (4.5 in this case).

With .NET <=3.5, you could have cases where multiple versions of the same assembly will be loaded (so, it could happen that ADO.NET will load version 4.0 and also load 4.5 in the same app domain). As far as I know, they either eliminated that with CLR 4.0 (or at least made it happen way less).

Edit: BTW - there's a difference between the CLR (the runtime running your code) and the versions of the assemblies being loaded.

The version of the CLR governs the capabilities of the process - what it can do, which versions of assemblies it can load. For example,, CLR 4.5 can load pretty much all assemblies (1.0 -> 4.5). They will all run under the 4.5 CLR. On top of that, you cannot run two versions of the CLR from the same compat band in the same process. CLR 4.5 and 4.0 both are considered the same compat band, so either one or the other will load. CLR 1.0, 1.1, 2.0, 3.0 and 3.5 are all considered in the same compat band, so only one of them can load. You can, however, load CLR 3.5 and CLR 4.5 at the same time.

like image 113
Shahar Prish Avatar answered Oct 12 '22 14:10

Shahar Prish