I am debugging some C# class (let's say, Foo) which has a Dispose-Finalize pattern implemented, i.e. its Finalizer is calling Dispose() in case if Dispose has not already been called.
Within the Dispose() there is logging code which accesses some member of Foo (let's say Bar). Bar is also an instance of some reference type, is readonly (created in the Foo's constructor) and is not exposed anywhere outside of Foo. So, at the time of Foo's garbage collection Bar is likely to be already collected as well. The theory says that such member fields should not be accessed from the Finalize thread.
But the logging code was not aware of theory and tryed to log some of the Bar's properties. And the process crashed with NullReferenceException in the Finalizer's thread.
I understand that bad things may happen when you ignore the theory, but I was not expected NRE: does the Garbage Collector srts the references to collected objects to null? Or am I missing something else?