I had a nasty bug in one of my pet projects. I had a callback function from COM object. Occassionally the program blew up with this error:
"An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module."
Not much of and error, right? Well, this happened from time to time and I didn't have any will to solve it.
But tonight it struck me! The callback function was referenced only from COM object and a local variable in the method. So the garbage collector disposed it at will and blew everything to pieces.
All I had to do was keep the function referenced - I just made a local variable private field of a class and it all works like a charm.
I think I just lost a nightmare that was hunting me for some time! Yeah!