My editor warns me that a line might throw on occasions, the relevant lines are:
var sf = new StackFrame(1, true);
line = sf.GetFileLineNumber();
file = sf.GetMethod().DeclaringType.ToString();
The warning: Possible System.NullReferenceException.
It underlines this specific part:
sf.GetMethod().DeclaringType
How could it throw null? Don’t you always need a method to invoke the caller, and if you have the method, isn’t DeclaringType it’s name? Do methods without name exist?
Adding nullable token ? after DeclaringType makes the warning go away, but I’m still wondering how it could be null.