Abhijeet
Abhijeet

Reputation: 13916

Old class library on new .NET projects

Sorry I am old school programmer, where all projects of a solution used to target the same .NET Framework version. However I see developers creating .NET 4.6.1 projects referencing .NET 4.5.1 class libraries.

Is it ok to reference older version of class library inside newer MVC / Web Api project?

For green field projects, by mixing different run times are we not headed in similar situation like DLL hell, not to mention performance penalty, if any, caused by simultaneous loading of run times in production server.

Upvotes: 1

Views: 1924

Answers (2)

Barr J
Barr J

Reputation: 10927

Long answer short - Yes. It is not a best practice, when Dealing with old libraries you need to make sure:

1) The methods and objects in the old class are still up to date and are compatible with your current .net frameworks. You need to make sure as well that you do not use deprecated methods.

2) You have to make sure the old class will compile and run on the new .net framework as well.

This approach is very convenient because if your old class works well with the new .net framework, you do not need to rewrite the whole class again to feet for the new framework.

If everything is a part of your solution and is working without problems, there should be no reason why not to, just make sure you check everything fits and the pieces are working together.

The downside is the fact, that if you want to migrate you class to a higher framework, you will have to rewrite your whole class code to fit for the framework, this is if it doesn't fit.

Upvotes: 2

DaveShaw
DaveShaw

Reputation: 52818

There are only 2 Runtimes these days (4 if you include 1.0 and 1.1). There is 2.0 and 4.0 and then different versions of those on the machine you run it on. So you can target your projects at .NET 4.5.1 and it will happily run in the 4.6.1 runtime.

If everything is part of one solution that ends up as one process, it makes sense to keep all the target plaforms the same, but there is no penalty for a .NET 4.7 app adding a reference to 3rd party library that only target's 4.5 - for example.

I have to write code targeting .NET 4.0 and for Desktops, but a newer .NET on the server side. I have a lot of projects with common code in the .NET 4.0 that I reference from both the Desktop and Server projects.

Upvotes: 3

Related Questions