title: Handle missing .NET Framework (0xc0000135) crash better?
body: <p>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:</p>
  
  <pre><code>---------------------------
  ThisApp.exe - Application Error
  ---------------------------
  The application failed to initialize properly (0xc0000135). 
  Click on OK to terminate the application. 
  ---------------------------
  OK   
  ---------------------------
  </code></pre>
  
  <p>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.</p>
  
  <p>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 <a href="http://www.example.com/" rel="nofollow noreferrer">http://www.example.com/</a>")</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Alright, I did some further testing and found out something quite interesting.</p>
  
  <p>On a clean <strong>Windows XP</strong> SP3 install (with <strong>no .NET</strong> 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:</p>
  
  <pre><code>---------------------------
  path\to\ThisApp.exe
  ---------------------------
  path\to\ThisApp.exe is not a valid Win32 application.
  ---------------------------
  OK   
  ---------------------------
  </code></pre>
  
  <p>Now the interesting thing with Windows Vista and further is that these actually take the <strong>ThisApp.exe.config</strong> file into consideration when launching the app.</p>
  
  <p>On a clean <strong>Windows Vista</strong> SP2 install (with <strong>.NET 3.5</strong> installed by default), targeting .NET 4.0 and above <strong>with .exe.config</strong> causes the following message to appear:</p>
  
  <pre><code>---------------------------
  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   
  ---------------------------
  </code></pre>
  
  <p>Now <strong>without .exe.config</strong>, this shows up instead:</p>
  
  <pre><code>---------------------------
  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   
  ---------------------------
  </code></pre>
  
  <p>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.</p>
  
  <p>Now on a clean <strong>Windows 7</strong> SP1 install (with <strong>.NET 4.0 Client Profile</strong> installed by default), targeting .NET 4.0 (Full) and above <strong>with .exe.config</strong> causes <a href="https://stackoverflow.com/a/10033128/17034">the message that was mentioned here</a> to appear:</p>
  
  <pre><code>---------------------------
  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   
  ---------------------------
  </code></pre>
  
  <p>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.</p>
  
  <p>However, <strong>without .exe.config, the app launches normally</strong>, 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.</p>
  
  <p>I have not been able to test on Windows 8/8.1, but I imagine it's the same as Windows 7.</p>
  
  <p>Either way, this is not a solved problem, at least not on Windows XP, which still has a large installed base.</p>
  
  <p>Also, <strong>please stop telling me to use an installer</strong>. I know. That is not what this question is about.</p>