Bite my bytes

What I learn by day I blog at night - A blog from Microsoft Consultant working from Ljubljana, Slovenia

  Home :: Contact :: Syndication  
  999 Posts :: 7691 Comments :: 235 Trackbacks

Search

Most popular posts
in last 180 days

Categories

My Projects

Archives

Stuff


Copyright © by David Vidmar
 
Contact me!
 
LinkedIn Profile
 
 
 

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!

Posted on Thursday, June 09, 2005 12:10 AM | Filed under: Developement |

Feedback

# Re: Garbage collector is a dirty bastard (if you don't know how it works) 6/9/2005 3:10 PM miha at rthand nospam com (Miha
Right, dealing with GC outside managed code is full of traps. Very delicate world that is.

Miha Markic [MVP C#]
RightHand .net consulting and software development
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
www.rthand.com

# re: Garbage collector is a dirty bastard (if you don't know how it works) 11/18/2005 3:54 AM pettaling
hi i am getting the same error..

can you provode solution for me?

In my .Net project my callback function is in the Module1.vb. when ever the user click the button in form1.vb i am passing the calback reference to the function in C DLL. then the function in C Dll will invoke my callback function in reguler interval. It's running but i am getting the following error occassionally.

An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module."


where i have to made a local variable?

Please help me out

# re: Garbage collector is a dirty bastard (if you don't know how it works) 11/21/2005 8:16 PM David
You probably have exactly the same error as I did. Try making the reference available, for example make it a private filed of the form.

# re: Garbage collector is a dirty bastard (if you don't know how it works) 6/8/2006 4:47 AM Foz
You are awesome - This one post must have saved me 20 hours of debugging!

Comments have been closed on this topic.