This is a type of esoteric. I encountered a NullReferenceException while trying to open a form (in winforms design) in a winforms project in visual studio 2008. The stack trace points to the fourth line of the following code:
public static class Logger { public static void LogMethodEnter() { var frame = new StackFrame(1); var method = frame.GetMethod(); Trace.TraceInformation("{0}.{1}.{2}()", method.DeclaringType.Namespace, method.DeclaringType.Name, method.Name); Trace.Indent(); } public static void LogMethodExit() { Trace.Unindent(); } }
... means a line with an opening brace. I ran into the same problem (but not with the participation of the winforms designer) in other projects, and I think it was a thread related problem, but I don't have code to replicate it.
Why is this happening and why does the exception stack trace point to a line with a curly brace?
Clarification: The null reference only exception occurs only in the winforms designer. When the application starts, it does not cause this error.
c # static nullreferenceexception visual-studio winforms
Zachary yates
source share