First of all; I do know what a NullPointerException is. I am well aware of What is a NullPointerException, and how do I fix it?.
In my WinForms application I am getting a NullReferenceException at the Application.Exit call with the following Stacktrace:
System.NullReferenceException occured. HResult=0x80004003 Message = The Object-Reference was not set to an instance of the object Source = Microsoft.VisualBasic StackMonitoring: at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.MainFormLoadingDone(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Originally the message was german due my VS17 beeing german, which I will definitly change to english later on. I translated the few german parts to english.
Also my VS17 shows me where it says
Application is on Hold
Your application was paused, but there is no code to show, because all threads executed external code (usually system- or frameworkcode).
After some research I found out, that most times the error occured on Form Closing and Form Closed events. Since I have not created any closing events myself I do not think that I will find my solution on those.
Calling Environment.Exit(1) instead of Application.Exit() does work, but since this one basicly just kills the process I would like to not use it.
Do you guys have any ideas where to look for the error?
Exception was probably due to the following:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Environment.GetCommandLineArgs.Contains("Confirmation") Then
Dim a As New confirmationForm
a.ShowDialog()
Application.Exit()
End If
End Sub
There was also an Application.Exit()
Call on a.Button1_Press()
event. This probably caused the exception. Will update as soon as I have fixed it.
Solution can be found in the answer + comments