3

When attempting to launch a C#/.NET application on a Windows XP installation without the correct .NET Framework installed, the app simply crashes with the message:

---------------------------
ThisApp.exe - Application Error
---------------------------
The application failed to initialize properly (0xc0000135). 
Click on OK to terminate the application. 
---------------------------
OK   
---------------------------

Which is honestly pretty meaningless to a Joe User, especially since the error code could refer to things other than .NET Framework not being present.

Is it somehow possible to crash with a more meaningful message? (Something like "This application requires .NET Framework 3.0 to run. Please download it at http://www.example.com/")

Edit:

Alright, I did some further testing and found out something quite interesting.

On a clean Windows XP SP3 install (with no .NET Framework installed), the app will always crash with the above message, regardless what .NET Framework version it's targeting, except .NET 4.5 and .NET 4.5.1, which show an even worse message:

---------------------------
path\to\ThisApp.exe
---------------------------
path\to\ThisApp.exe is not a valid Win32 application.
---------------------------
OK   
---------------------------

Now the interesting thing with Windows Vista and further is that these actually take the ThisApp.exe.config file into consideration when launching the app.

On a clean Windows Vista SP2 install (with .NET 3.5 installed by default), targeting .NET 4.0 and above with .exe.config causes the following message to appear:

---------------------------
ThisApp.exe - .NET Framework Initialization Error
---------------------------
To run this application, you first must install one of the following versions of the .NET Framework:

  v4.0

Contact your application publisher for instructions about obtaining the appropriate version of the .NET Framework.
---------------------------
OK   
---------------------------

Now without .exe.config, this shows up instead:

---------------------------
ThisApp.exe - .NET Framework Initialization Error
---------------------------
To run this application, you first must install one of the following versions of the .NET Framework:

  v4.0.30319

Contact your application publisher for instructions about obtaining the appropriate version of the .NET Framework.
---------------------------
OK   
---------------------------

A very minor change, I know, but I'm going somewhere with this. It's interesting to note that the version number (v4.0 or v4.0.30319) stays the same even when targeting .NET 4.5 and 4.5.1.

Now on a clean Windows 7 SP1 install (with .NET 4.0 Client Profile installed by default), targeting .NET 4.0 (Full) and above with .exe.config causes the message that was mentioned here to appear:

---------------------------
ThisApp.exe - .NET Framework Initialization Error
---------------------------
To run this application, you first must install one of the following versions of the .NET Framework:
  .NETFramework,Version=v4.0

Would you like to download and install .NETFramework,Version=v4.0 now?
---------------------------
Yes   No   
---------------------------

Now this message is more like it. The version also changes to v4.5 and v4.5.1 when targeting .NET 4.5 and 4.5.1 respectively.

However, without .exe.config, the app launches normally, even when targeting .NET 4.0 (full) and higher (even 4.5). I imagine that if I was actually using any features of .NET 4.0 full or 4.5 and higher, the app would crash eventually, but I still think it's pretty interesting. Hypothetically, you would be able to check for the correct version of .NET inside the app itself.

I have not been able to test on Windows 8/8.1, but I imagine it's the same as Windows 7.

Either way, this is not a solved problem, at least not on Windows XP, which still has a large installed base.

Also, please stop telling me to use an installer. I know. That is not what this question is about.

Community
  • 1
  • 1
Zdeněk Gromnica
  • 854
  • 2
  • 14
  • 31
  • 6
    Souldn't that be done by your installer? – Adriano Repetti Apr 14 '14 at 14:31
  • 6
    You could/should install your application with a setup that checks for .NET and installs it if it is missing. – Uwe Keim Apr 14 '14 at 14:32
  • 5
    If you aren't using an installer (you should) then perhaps use a boot strapper app that targets a lower framework version and have it test for the higher framework version and if present, launch the actual app? – Chris McAtackney Apr 14 '14 at 14:32
  • 1
    It is a [solved problem](http://stackoverflow.com/a/10033128/17034). The only possible mistake you could make is ignoring the past 4 years of .NET improvements. – Hans Passant Apr 14 '14 at 16:16
  • @HansPassant Interesting. I did some testing and updated my question. Unfortunately, it's still not a solved problem for Windows XP. – Zdeněk Gromnica Apr 15 '14 at 12:45
  • The comments in the linked post note that this works on XP as well. I suppose the user won't have any luck at all if his XP install is completely virgin. As hard as this is to imagine for a 13 year old operating system. These are not the kind of user you'd ever want to support btw. Solving it is simple enough, just document it as a prerequisite for your program. Just as you'd insist that the user has a machine that boots Windows XP SP3 or better instead of Linux or Windows 98. – Hans Passant Apr 15 '14 at 13:35
  • @HansPassant I tested it, and it definitely doesn't work on XP, as stated in the question. I suppose it might work if you have .NET 4.0 Client Profile (or perhaps even 3.5?) already installed, but that hardly solves the issue. And yes, I suppose it is a valid prerequisite, but I'd stil like to know if there is an answer to this, since it would be nice to at least tell the user what went wrong instead of a cryptic error message. – Zdeněk Gromnica Apr 15 '14 at 13:43

1 Answers1

1

Which is honestly pretty meaningless to a Joe User,

Joe user only should start programs that have been installed. It is the responsibility of the installer to handle prerequisites.

Is it somehow possible to crash with a more meaningful message?

No, becaused you do not crash. Not in .NET. When .NET was created, microsoft made the files backward compatible. It is the native initialization code in the executable that blows - not something in your .NET code. Without runtime, the .NET code can not run.

Funny enough, this is a solved problem. You are using a totally outdated version of .NET as this has been fixed in the latest versions (.NET 4.0 upward) with a more meaningful dialog.

http://blogs.msdn.com/b/dotnet/archive/2012/03/07/optimizing-the-net-framework-deployment-experience-for-users-and-developers.aspx

has a reference. Depending on windows version that leads directly to a download/install dialog.

.NET 3.0 is quite ancient.

mrid
  • 5,782
  • 5
  • 28
  • 71
TomTom
  • 61,059
  • 10
  • 88
  • 148
  • I'm not going to comment on what Joe User should or shouldn't do, or the technicalities of .NET apps, but you are wrong – it has not been fixed with .NET 4.0. Please see my updated question. – Zdeněk Gromnica Apr 15 '14 at 12:50