Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run .NET 4 applications inside my .NET 2 application? [duplicate]

Possible Duplicate:
Can I use a .NET 4.0 library in a .NET 2.0 application?

So I have a legacy .NET 2 GUI application. Redoing this application is out of the question.

I also have a console .NET 4 application that does FTP and other work. It uses LINQ.

Now, I am abstracting the console application (which is .NET 4) into reusable DLLs, etc.

What I want to be able to do is have the GUI app (.NET 2) be able to include those DLL's and call them. Then just get return values from it.

I think worse case I could just keep it a console app and have the .NET two execute it externally. But I would like the GUI app to be able to execute methods from the .NET 4 piece.

The clients that will be running this app all have .NET 4.

Thanks.

like image 476
cbmeeks Avatar asked Oct 22 '12 15:10

cbmeeks


2 Answers

So I have a legacy .NET 2 GUI application. Redoing this application is out of the question.

Is changing the framework target to .NET 4 and rebuilding also out of the question? That would probably be the simplest approach - then you'd know you wouldn't end up in strange situations where you were actually running on CLR v2 and trying to load assemblies which required CLR v4 (and .NET framework v4 assemblies).

In most cases you should simply be able to retarget - while backward compatibility isn't 100%, it's pretty good.

like image 165
Jon Skeet Avatar answered Oct 16 '22 15:10

Jon Skeet


What you need to do here is factor out the shared utilities into DLLs that target the 2.0 framework. These DLLs can then be used in both a 2.0 and 4.0 .Net process. .Net places a very high bar on backwards compatibility and in the vast majority of scenarios a 2.0 DLL can be run without changes in 4.0.

like image 42
JaredPar Avatar answered Oct 16 '22 13:10

JaredPar