Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fail gracefully if .NET is not installed?

Tags:

.net

I've recently asked if you can detect from the application if .NET is installed (so that application will not crash with a general exception fault).

The answer seems to be a plain "no". I still want to be able to exit gracefully if .NET is not installed, is there any way to do this?

Keep in mind that I don't want to change the executable name, meaning it's ok to have an unmanaged executable doing the check and a dll doing having the real .NET program but not having to executables.

Edit: I don't mean failing from the installer, there's no installer at all, just the executable. Of course it's highly unlikely for this to happen but still I'd like to be able to check it anyway.

like image 943
Jorge Córdoba Avatar asked Feb 27 '09 10:02

Jorge Córdoba


1 Answers

You have two different options:

  • Write a small native code loader that checks for the runtime and executes your software if the runtime is installed. Otherwise it could just give user an error message, point him to the download location for the runtime, etc.

OR

  • Make sure that your installer installs the runtime. Joe Coehorn mentioned it would be easy to do with MSI in this post and you should also be able to do it with other installers such as InnoSetup. Of course if someone first installs your software, then re-installs windows, and then tries to run your application without re-installing it as well, it will crash.

And of course you could combine both for the best of both worlds.

like image 120
Adrian Grigore Avatar answered Oct 08 '22 21:10

Adrian Grigore