9

How far along does software compiled for .NET 3.5 get before crashing on a system that only has .NET 2.0 installed?

The application I am developing uses WPF and requires .NET 3.5, but I would like to display a user-friendly dialog (rather than crashing) if the user does not have it installed.

Are there any standard ways to do this, or official Microsoft documentation on it?


EDIT: In an ideal world I'd just check that any .NET dependencies are satisfied during installation. Since some applications do not have installers and since users could potentially uninstall .NET after the application is installed, I find the answers below to be useful.

M. Dudley
  • 26,519
  • 30
  • 137
  • 228
  • This probably depends a bit on if your program depends on any 3.5 assemblies (like LINQ for example). I'm intently curious though myself. – Matthew Scharley Oct 05 '09 at 14:47

3 Answers3

6

It (probably) wont crash until it tries to use a dll that needs 3.5. If the executing app can check the version before using any 3.5 specific dlls, you can display a winform dialog and you should be ok. Your safest bet would be to make the exe be a 2.0 assembly and make all of your 3.5 stuff in a separate dll that is compiled against 3.5. You could do your check in the 2.0 dll before it loads any of your 3.5 assemblies.

NotDan
  • 30,143
  • 35
  • 111
  • 154
3

.NET 3.5 uses .NET 2.0 runtime, so an app will start perfectly fine (however, it will fail when it will attempt to load 3.5 assemblies). You can check Environment.Version to see if it's .NET 3.5 you're running on and present user with standard MessageBox.Show if not.

Anton Gogolev
  • 107,051
  • 37
  • 191
  • 278
  • 1
    Environment.Version only indicates the version of the CLR, not the .NET assemblies installed. The official way to check the version is via the registry: http://stackoverflow.com/questions/199080/how-to-detect-what-net-framework-versions-and-service-packs-are-installed – M. Dudley Oct 05 '09 at 14:59
3

Have you considered using ClickOnce deployment? The agent will check for and install any prerequisite items you specify, including .Net. It also makes pushing upgrades of your application fairly painless.

Rob Allen
  • 15,975
  • 4
  • 47
  • 69
  • You can't rely on this - particularly in corporate environments where the users won't have admin access to the machine – ChrisF Oct 05 '09 at 15:22
  • If they lack the necessary rights to install, then any install method will fail. – Rob Allen Oct 05 '09 at 15:31
  • In my particular situation the application will be deployed to systems that do not have network access. I have not used ClickOnce before, but it does seem like a nice solution for most situations. – M. Dudley Oct 05 '09 at 15:34
  • 1
    @emddudley, You can include the install files on an Install CD. See here for how: http://msdn.microsoft.com/en-us/library/ms172610.aspx – Rob Allen Oct 05 '09 at 15:47
  • Note that ClickOnce requires .NET 3.0 or 3.5 to be installed to work. If the user only has .NET 2.0 installed the ClickOnce installer will not set it up for him, it will direct him to Microsoft's website. – M. Dudley Oct 07 '09 at 15:04
  • @emddudley - thats strange. I thought the whole point was that it would set up _any_ prereqs on click. – Rob Allen Oct 08 '09 at 13:38
  • @Rob Allen: Perhaps you are right. http://stackoverflow.com/questions/955309/clickonce-app-says-requires-net-3-5-when-built-using-net-2-0 – M. Dudley Feb 08 '11 at 18:31