3

I'm trying to fix a bug that I cannot reproduce (yipeee!). I have the stack trace that was copied by the user that originally discovered the issue, and it shows the code throwing a null reference exception (which is unhandled) on a line that is checking the object for null..like this:

private void someFunction()
{
    radioButton1.CheckedChanged -= checkedChangedEventHandler
    radioButton2.CheckedChanged -= checkedChangedEventHandler

    if (someObject != null)  // throws NullReferenceException...allegedly
    {
         if (someObject.Property == something)
         {
            // set properties on some UI components
         }
    }
}

What kind of conditions could cause this?

UPDATE

Added some more code. SomeFunction method gets called by the checkedChanged event handlers.

UPDATE 2

The stack trace must be wrong as several of you have suggested. There are no operator overloads, and the method only references four objects that are not UI components (labels and radio buttons), and all of those objects are assigned only once on initialization, and are referenced multiple times before ever getting to this code so any null references would have been caught way before this. I'll have to look more closely at the calling event handler function.

Here is a thread explaining stack traces with wrong line numbers:

Wrong line number on stack trace

8
  • Mark it norepro in your bug tracker and move on! =) Commented Jul 1, 2011 at 18:53
  • 1
    Can you show us the stack trace? Commented Jul 1, 2011 at 18:54
  • Is there more code around this that we could see? Commented Jul 1, 2011 at 18:54
  • How confident are you that the present version of the code matches the stacktrace? Commented Jul 1, 2011 at 18:54
  • 6
    Sometimes an exception can appear to have been thrown on the line following the one where it was actually thrown. Have you checked the line above? Commented Jul 1, 2011 at 18:54

3 Answers 3

8

someObject has overloaded != operator?

http://msdn.microsoft.com/en-us/library/8edha89s(v=vs.71).aspx

Sign up to request clarification or add additional context in comments.

2 Comments

...and did a terrible job of it!
Nope...it doesn't overload the != operator. The object implements several interfaces, none of which overload anything.
4

The two most likely candidates are:

  1. An overloaded != operator is causing havoc (though you'd think the stack trace show that.)
  2. The stack trace is wrong, and you need more information to go forward.

I think 2 is more likely.

1 Comment

It looks like it must be #2. I'll post an update if I actually find the cause.
0

I just wanted to post this in here for anyone who stumbles across this thread. dlev gets the correct answer for suggesting it, but I thought it was still relevant to post as an answer:

Wrong line number on stack trace

stack trace line numbers are wrong with debug=false and compilerOptions="/debug:pdbonly"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.