Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to support .NET 2.0 and .NET 4.0 in one application?

Tags:

.net

clr

Here's an interesting one. I have a small executable that is built against .NET 2.0, to ensure it operates on a wide variety of platforms. It is a one-assembly program and it references only System.* namespaces.

When I run it on an OS with .NET 2.0 installed, it runs fine. It will not run on an OS with only .NET 4.0 installed, because of the new runtime introduced with .NET 4.0. As a result, I added supported runtime information to the app.config file, as described here. I added two supported runtimes:

<supportedRuntime version="2.0.50727" />
<supportedRuntime version="4.0" />

Now when I run the application on a system with .NET 2.0 installed, it fails to run:

enter image description here

It makes no difference in which order the supported runtimes are defined, other than the order of the requested versions in the error message changes to reflect the changes to the app.config (so the CLR is obviously picking up that information properly). I have .NET 2.0 installed, and it is claiming that I need to install .NET 2.0! I have tried repairing the installation of .NET 2.0 with no luck. I have reproduced this behaviour on a second machine.

What could be causing this to fail?

like image 821
alastairs Avatar asked Sep 06 '11 14:09

alastairs


1 Answers

I believe you may just have missed out the v:

<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
like image 56
Jon Skeet Avatar answered Oct 13 '22 03:10

Jon Skeet