Take the 2-minute tour ×

Here's the thing. My .NET application crashes with a pretty ugly general exception fault when I try to run it in a machine that doesn't have .NET framework installed.

Is this normal? If it is... is there any way to check for .NET framework to be able to exit gracefully instead?

share|improve this question
The bigger question is: What machines do not have .NET installed? –  leppie Feb 27 '09 at 10:51
Asked before: stackoverflow.com/questions/558184/… –  Mehrdad Afshari Feb 27 '09 at 10:59
How is that question related to this one? I was asking for a way to check on runtime if .NET is installed, the other one was asking which .net framework versions come preinstalled on what OS. –  Jorge Córdoba Feb 28 '09 at 20:09

5 Answers 5

up vote 7 down vote accepted

You can't check the version number of the .NET framework with managed code as it can't execute before loading the .NET runtime. You can use the CLR Unmanaged API to do so, but the best way is to solve this problem is to provide an installation mechanism that checks, downloads and installs .NET Framework if it's not installed on the machine.

share|improve this answer

You could write a stub in non-managed code to do it, but prerequisites are normally why you create setup applications.

share|improve this answer

Take a look at the .NET Framework Client Profile (http://msdn.microsoft.com/en-us/library/cc656912.aspx):

The .NET Framework Client Profile provides a common bootstrapper setup that you can use for your client applications. This makes sure that all requirements for running your application are installed, regardless of which version of the .NET Framework, if any, is present. The setup experience provides a consistent user interface (UI) and seamless installation, whether the target operating system is Windows XP or Windows Vista.

share|improve this answer

You have to do that check in the installer script, I suppose.

share|improve this answer

If it's packaged in an installer you can set the install conditions to check for .NET and the framework version.

The other way to check the framework is:


From the O'Reilly Cookbook.

But both of those are defeated by the fact that .NET has to be installed before the code can even begin to check.

share|improve this answer

Your Answer


