Search code examples
vb.netwinformsvisual-studiogenerated-code

Can be generated source of VB.NET application framework grabbed somewhere?


I would like to turn off application framework in VB.NET WinForms project in order to use Application.SetUnhandledExceptionMode() method which must be injected into Main() before UI is initiated.

But after switching it off I'll lose automatic saving of settings and other features. I'm using at least that saving of settings (and who knows what else is in the automatically generated source what I'm relying upon...) So before disabling of application framework I'd like to obtain source code that Visual Studio inserts behind the scenes (app startup, app exit, ...) and make it explicit part of my source code. Is it possible to get that automatically generated code?

Note: I think sources in question can be seen for WPF project but what about WinForms project? Adapt those sources from WPF?

Even linking to full code for WinForms application framework will help. I'll sort out what is needed for my project.


Solution

  • A workaround:

    Funny enough, in meantime I found* that if app is run outside the VisualStudio, calling SetUnhandledExceptionMode() is NOT needed.

    Just handling of AppDomain.CurrentDomain.UnhandledException and System.Windows.Forms.Application.ThreadException is enough for proper handling.

    Inside VisualStudio, you always get UnhandledException but this is still an acceptable compromise – so application framework can be kept in place.

    *) https://social.msdn.microsoft.com/Forums/windows/en-US/9dbbe3b6-2e92-4a98-be62-28c933a7741e/error-calling-applicationsetunhandledexceptionmode?forum=winforms&prof=required (see dalkae69's reply)