Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running .NET 4.0 app with reference to 2.0 library on machine with only 4.0 framework

Tags:

c#

.net

version

clr

This would be a real pain to try to duplicate, so I'm hoping someone has a quick answer...

Suppose I have a .NET 4.0 application, with a reference to a .NET 2.0 library (SharpZipLib in this case). This of course works fine on a normal machine with .NET 2.0 and 4.0 installed.

If the server running this application has only .NET 4.0 and not 2.0 (or 3.0/3.5 etc.), what do I need to do to allow the .NET 2.0 library to run properly?

From what I've read, it looks like I may be able to put in a config setting for supportedRuntime, but I'm not quite understanding what exactly that does.

Will a config setting work, or would only .NET 4.0 libraries function in this environment?

(This is a hypothetical environment - I don't plan on ever having my own servers with 4.0 and not 2.0, but if someone is crazy enough to do it, I want to be able to support them).

Thanks

like image 833
Joe Enos Avatar asked Jan 14 '12 18:01

Joe Enos


1 Answers

The CLR can load older assemblies in the .net 4.0 framework.

Here's a good read:

http://msdn.microsoft.com/en-us/magazine/ee819091.aspx

EDIT: updated quote from article. Particularly notice the bold

The .NET Framework 4 runtime—and all future runtimes—will be able to run in-process with one another. While we did not back-port this functionality to older runtimes (1.0 through 3.5), we did make sure that 4 and beyond will be able to run in-process with any single older runtime. In other words, you will be able to load 4, 5 and 2.0 in the same process, but you will not be able to load 1.1 and 2.0 in the same process. .NET Frameworks 2.0 through 3.5 all run on the 2.0 runtime and so have no conflicts with one another, as shown in Figure 2.

like image 81
bryanmac Avatar answered Oct 10 '22 22:10

bryanmac