Why isn't subscribing to an event on a null object consistently throwing an exception?
I've got an C# application that is installed on a network. One particular user using the network installation is having issues with an 'Object reference not set to an instance of an object'.
However, if I look at the problem, it seems like every single user should be having the issue!
The problem lies开发者_JAVA百科 in two presenter classes. The first presenter sets the View on the second presenter. Within the second presenter, the View's setter attempts to subscribe the presenter to an event on the View.
However for a certain licensing level, that object will always be null.
To me, it seems like this should be failing all the time however even when running from VS2008, it only fails if I explicitly set a breakpoint on the statement where it attempts to subscribe to the null object. If I just load it without a breakpoint or with a breakpoint on a different, unrelated block of code then it works fine!
The faulty code is wrapped in a Try/Catch block so it shouldn't be able to just ignore the exception or swallow it somewhere else.
Thanks.
Obvious answer: You're not getting a NRE every time because the object isn't null every time. Your assumptions are incorrect, and an in-depth code review probably would reveal what's happening.
精彩评论