Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My Windows From project debugs correctly. But after I will click "Sign Out" button (It's used Application.Restart() function) then comes this error. Please give me some advice.

ERROR:-
System.NullReferenceException: 'Object reference not set to an instance of an object.'

What I have tried:

Can't find where the issue? Because always this error comes Application.Exit and Application.Restart function. Sometimes, open forms not close. But how can fix it?
Posted
Updated 3-Apr-18 20:51pm
Comments
Christiaan van Bergen 4-Apr-18 2:50am    
Can you show us the stack trace? It appears you are running code on application exit.

1 solution

We can't tell you - there could be many reasons such as a form closing / form closed handler that expects something to be available which has been disposed.

But what I suspect is that "My Windows From project debugs correctly" does not mean what you think it means: compiling is not debugging. Your project clearly doesn't "debug correctly" because it is throwing a null reference exception...
Think of development as writing an email: compiling is the process of making sure that the message is written in the right language: English words, not German for example, and that they are in the right order.
Debugging is the process of making sure that the message means what you intended it to.
This email will compile:
Quote:
Oi! Send me some stuff!
And so will this:
Quote:
Hi Jane! Thanks for the call this morning, I'd like to confirm an order for 8 off your part number 45422, 6 off your partnumber 87865, and 1 off your part number 12553. My account number is 546223, my purchase order number is 1144, and if you could dispatch that via DHL 24 hour that would be great, as I need them here for start of play Friday.

Best regards,
Joe Smith, MyCompany Ltd.
But only the second debugs correctly and gets you the good you want!

Use the actual debugger - when the exception occurs, it should stop on the line that caused it and allow you to look at the variables and work out which one is null. From that, you should be able to find out why it is null. But that isn't something we can do for you - we don;t have your code, and can't run it under the same circumstances if we did.

And to be honest, using Application.Restart to log a user out is just pure laziness...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900