I just spent hours and hours trying to get at the cause of a NullReferenceException being thrown by my application. I could not trap it, inspect it or even get rid of it by grabbing a straws. Finally I cleared out all of the breakpoints in the app and ran it again and the problem disappeared.
I remember discovering something similar to this a year and a half ago with an Infragistics grid. When I had the debugger set to break on CLR exceptions, I was getting stuck every time I set some properties in the grid and could NOT figure out where the error was coming from. It turned out that it is something like a first chance exception that is actually handled by the grid before it comes out to your code. So once I removed the setting for breaking on CLR exceptions, I could get past that. Here's a blog post I wrote about it then.
Today's nonsense was revolving around a web service that is being secured by WSE 3.0. I am using SecureConversation, so the proxy gets cached and reused so that the SecurityContextToken can be used for multiple messages. The pattern was always the same. I made call #1, which gets the SCT and then performs the operation, then call #2 which performs another operation and then call #3 which is a repeat of the operation in call #2. On call #3, whenever I made the call to the proxy, I got the NullReferenceException.
Everything involved in that line of code was a non-null object. I was following a suspicion that the SCT had somehow timed out and I hadn't handled it properly, but that didn't pan out.
Another clue for me was that I was not even getting into the WSE 3.0 pipeline that takes my web service message and processes it into a nicely configured message for ws-security. There was not anything in the trace regarding that outgoing message.
I truly spent many hours trying to figure this out. My mother called while I was working on it and I just wanted to cry and say "Mommy, the computer is being mean to me."
Finally in frustration, I turned off all of the breakpoints and hoped that maybe something would get out to the trace. But to my shock, the error disappeared into thin air and I realized that I had just experienced the same problem as with the Infragistics control. My guess is that the WSE 3.0 API was throwing that error, but without any data because they expected it to never be exposed outside of their own goo.
So I think I'm going to call it a night and trick myself into thinking that some of my Valentine's chocolate will cure the wicked headache I have right now.