none
How to avoid app crash if .NET framework uninstalled/disabled RRS feed

  • Question

  • In Windows 7, it is possible to disable the .NET framework via the Control Panel's "Turn Windows features on or off".

    If this is done, running a .NET application causes an app crash, which is logged to the Windows Event Log, and also generates an application crash report that is sent back to Microsoft (WER).

    How can we avoid this app crash?  Because the app requires .NET, I don't think it can perform a check for the framework's presence itself.  Providing an application configuration file with "requiredRuntime" specified does not avoid the app crash.

    The only solution we can come up with is writing an unmanaged wrapper around every managed application. The unmanaged code could check for the framework being installed, and then launch the managed process.  This could be tedious to do for every application.

    Ideally, this would just fail more gracefully and let the user know that the .NET framework is required but not available.  This solution should probably come from the OS, but we're looking for a way to be able to handle this ourselves for now.

    Any ideas appreciated. Thanks, David

    Wednesday, September 8, 2010 2:49 PM

Answers

  • Actually SetUnhandledExceptionFilter can't work in this case, considering .NET is not installed no code from the application can execute and unfortunetly you can't install an exception filter without running the code install it. (my bad) 

    I was going through this article http://msdn.microsoft.com/en-us/magazine/cc301805.aspx, it berifely discribes the format of a .NET executable.

    To the operating system, .NET executables are just plain old Win32 executable files. However, the .NET runtime recognizes data within these executable files as the metadata and intermediate language that are so central to .NET. In this article, I'll knock on the door of the .NET metadata format, but save a thorough survey of its full splendor for a subsequent article.

    Now, if .NET is not installed, thate means you dont have the component (CLR) to recognize the right data in the PE, therefore the initialization process fails. This situaltion is same as if you are running a native application and one of the statically linked module is not found. Since the application is not initialized yet you can't handle any kind of exception or error from within the application code. You need someone else to handle it. As you pointed the third person may be the native launncher application, which detects the presence of .NET and launches the application. Or some debugger which is set to be invoked as soon as your application crashes.

    I hope it helps.

     


    My next phone is Windows Phone 7
    • Edited by Prateek Kr Dubey Wednesday, September 8, 2010 8:26 PM fixed a typo
    • Marked as answer by eryang Friday, September 17, 2010 8:33 AM
    Wednesday, September 8, 2010 8:25 PM

All replies

  • I dont know right answer of this question but I will give a shot to SetUnhandledExceptionFilter. Can you try this ? 
    My next phone is Windows Phone 7
    Wednesday, September 8, 2010 4:49 PM
  • No good.  I can't get my exception handler to be called, so the app crashes.  I'm guessing the event handling mechanisms require .NET.
    Wednesday, September 8, 2010 7:40 PM
  • Actually SetUnhandledExceptionFilter can't work in this case, considering .NET is not installed no code from the application can execute and unfortunetly you can't install an exception filter without running the code install it. (my bad) 

    I was going through this article http://msdn.microsoft.com/en-us/magazine/cc301805.aspx, it berifely discribes the format of a .NET executable.

    To the operating system, .NET executables are just plain old Win32 executable files. However, the .NET runtime recognizes data within these executable files as the metadata and intermediate language that are so central to .NET. In this article, I'll knock on the door of the .NET metadata format, but save a thorough survey of its full splendor for a subsequent article.

    Now, if .NET is not installed, thate means you dont have the component (CLR) to recognize the right data in the PE, therefore the initialization process fails. This situaltion is same as if you are running a native application and one of the statically linked module is not found. Since the application is not initialized yet you can't handle any kind of exception or error from within the application code. You need someone else to handle it. As you pointed the third person may be the native launncher application, which detects the presence of .NET and launches the application. Or some debugger which is set to be invoked as soon as your application crashes.

    I hope it helps.

     


    My next phone is Windows Phone 7
    • Edited by Prateek Kr Dubey Wednesday, September 8, 2010 8:26 PM fixed a typo
    • Marked as answer by eryang Friday, September 17, 2010 8:33 AM
    Wednesday, September 8, 2010 8:25 PM
  • Hi David,

    I'm writing to check the issue status, does Prateek's suggestion help? please feel free to let us know if you have any concern.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, September 10, 2010 6:16 AM