G
Guest
Hi
I'm facing a very strange problem here. My code looks like this
if(A == null
return
doSomethingWith(A.b)
When I run my code (in debug mode), I get a NullReferenceException -- and on breaking, I discover that A is indeed null. (The exception is raised in the doSomethingWith line.
How can this be? No code has been executed between the IF statement and the next statement. In the context I run the code, A *shouldn't* be null, and even if it were - why does it not step into the IF statement and return
What's worse, when I set a breakpoint anywhere near this segment in my code, the problem *disappeaers* -- A isn't null, and everything works properly
This looks like the classic '=' instead of '==' mistake I'm used to from C++, but that's not the case here (I checked, and anyway C# IF statements require bool...). The fact that it disappears on extensive debugging makes me think it's some sort of debugger/runtime-environment bug. I thought it might be related to garbage collection, but that doesn't make sense either (since I have a reference to A, it shouldn't be collected, right?)
Does anyone have any idea what's going wrong
(For completeness' sake, I should mention that the code I'm running was developed for the 1.0 Framework, and I'm now running it with 1.1.)
I'm facing a very strange problem here. My code looks like this
if(A == null
return
doSomethingWith(A.b)
When I run my code (in debug mode), I get a NullReferenceException -- and on breaking, I discover that A is indeed null. (The exception is raised in the doSomethingWith line.
How can this be? No code has been executed between the IF statement and the next statement. In the context I run the code, A *shouldn't* be null, and even if it were - why does it not step into the IF statement and return
What's worse, when I set a breakpoint anywhere near this segment in my code, the problem *disappeaers* -- A isn't null, and everything works properly
This looks like the classic '=' instead of '==' mistake I'm used to from C++, but that's not the case here (I checked, and anyway C# IF statements require bool...). The fact that it disappears on extensive debugging makes me think it's some sort of debugger/runtime-environment bug. I thought it might be related to garbage collection, but that doesn't make sense either (since I have a reference to A, it shouldn't be collected, right?)
Does anyone have any idea what's going wrong
(For completeness' sake, I should mention that the code I'm running was developed for the 1.0 Framework, and I'm now running it with 1.1.)