שתף באמצעות


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

Question

Thursday, October 31, 2019 10:06 PM

I am getting the following error: 

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

On the side is a Break Mode Box

The  top Line reads: "The application is in break mode"

Your app has entered a break state, but there is no code to show, because all threads were executing external code (typically system or framework code).

Suggested actions:

• Show Diagnostic Tools

• Check for running Tasks

• Continue Execution

What can I change in the "Tools" options so that I don't get this error message, rather it should show me exactly where the error is?

All replies (2)

Thursday, October 31, 2019 11:36 PM ✅Answered

Hello,

With pretty much no real details the following might help. Also, could this be from a third party library is one or more is used.

There are two paths to look at 

The first is under the IDE debug menu, select "Windows" -> Exception setting then check "Common Language Runtime Exceptions", run the app, see if the offending line is pointed to and determine a resolution or tell us what happened.

The second is to figure out approximately where this is happening, set a breakpoint prior to where it's happening and step through the code until it breaks.

Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

NuGet BaseConnectionLibrary for database connections.

StackOverFlow


Friday, November 1, 2019 3:09 AM

Hi,

possible reason:
If your application references a three-party library, be sure to pay attention to the target platform generated by the dll, otherwise the  "The application is in break mode" error may be reported during debugging.

Possible solution: Set the compiled target platform to be correct, note whether it is X86 or X64.

In addition, for possible reasons for System.NullReferenceException you can browse the following documents:
/en-us/dotnet/api/system.nullreferenceexception?view=netframework-4.8
As Kareninstructor mentioned above, you can set breakpoints to debug your code and find the place that throws the exception.

Best Regards,

Julie

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.