I get an application error thrown when I close the program using as cancel button which all it does is close the form.
The error says: "Application appName.exe encountered a serious error and must shut down"
How do I start fixing it? It is not a thrown exception; no other info is given. What could it be and how do I fix it?
Here is what it was. My application has two forms - login and main form where all the action happens. The login form has two buttons (Login and Cancel). Login button logs user in, closes the login form and opens the main form. Cancel button just closes the login form. To close the form I simply used this.Close().
What was happening though is that I still needed to dispose of the login form explicitly by doing something like:
frmLogin.Dispose();
frmLogin = null;
before exiting the program (in my Program.cs)
So this solved it. I had to make sure that this was being done in both cases: when the user logs in as well as when they choose to not log in.
Crucial fact is that frmLogin is modal, hence Dispose() is not called automatically when closed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With