Jader Dias
Jader Dias

Reputation: 90603

When both .NET 2.0 and .NET 4.0 binaries are provided, what are the advantages of using the latter?

I know the .NET 2.0 version is provided for compatibility purposes. But why some libraries have both versions? Is there any reason to publish a .NET 4.0 version of a library?

Take for example the Oracle.DataAccess library.

Upvotes: 0

Views: 118

Answers (2)

Hans Passant
Hans Passant

Reputation: 942518

Take for example the Oracle.DataAccess library.

Which would be a good example of an assembly that is mixed-mode. Written in C++/CLI and containing native code with managed class wrappers. Database providers very often need to use a native api to talk to the database server. Certainly the case for Oracle.

Using .NET 2.0 versions of such assemblies in a program targeting .NET 4.0 is a problem. They require an .exe.config file with the useLegacyV2RuntimeActivationPolicy attribute to convince the CLR that it is okay to have such an assembly execute on the 4.0 version of the CLR, even though it asks for 2.0. Not having the attribute produces a nasty startup error. Documentation is here.

Too painful. The simple solution is to just provide a separate .NET 4.0 version of such an assembly.

Upvotes: 3

Cody Gray
Cody Gray

Reputation: 245012

Generally, the version of a library that targets a newer version of the framework provides new features that require the new version of the framework in order to work properly. There are lots of new goodies introduced in .NET 4.0 that weren't present in .NET 2.0.

Developers like working with the latest framework, so all new code is going to be implemented targeting that framework. The older version, targeting the older version of the framework, is provided for compatibility reasons only, as it likely provides only a minimally-necessary subset of features.

Another possibility is that the newer framework provides performance or other improvements for the library code. Those can [sometimes] be backported to earlier versions of the framework, but they're often non-optimized implementations and should therefore be used only when absolutely necessary.

Upvotes: 3

Related Questions