System.NullReference exception in assembly release only

I get a "Fix System.NullReferenceException: Object not set on the instance of the object." An error occurred while starting the release build of my web application. He tells me to do a debug build to get more information, but when I run the debug build, the error no longer occurs. Without the help of line numbers that are set with most errors in debug builds, it is very difficult (from what I know) to determine the cause of this undefined error.

Can someone point me in the right direction to narrow down the reason for this exception?

Thanks.

+4
source share
2 answers

For a quick solution to your problem (if you don’t have time to rewrite the code), see the event log on the computer on which you launched the application. There is a great chance that you just skip some DLLs.

As a long-term solution, I think you can start by adding some logging functions to your application (corporate library, log4net, etc. or even your own registrar). Printing a full stack trace is an invaluable source of help, especially when you include .pdb files in your version. This will allow your executed code to indicate exactly which line threw the exception.

Hope this helps, Peter

+2
source

you can get the file names and line numbers in your stack traces, even if you create Release mode. See Display line count in Stack Trace for building .NET in decompression mode and Is stack information available in release mode of .NET version available? , eg.

In general, I think you should avoid introducing various programmatic behaviors in the Debug versus Release mode (but maybe you didn't introduce this intentionally?).

+2
source

Source: https://habr.com/ru/post/1438127/


All Articles