I encountered a case where the exception had a Message
, but the mere access of StackTrace
threw an exception!
This worth repeating: Just accessing the StackTrace
threw an exception, i.e. without even calling a method upon it (like ex.StackTrace.ToString()
).
This happened when working with COM libraries.
Specifically, it happened when a .NET Framework dll referenced an interop dll. For some reason the clr couldn't find and load that interop dll, and the exception thrown was a normal System.IO.FileNotFoundException
, which had a Message
.
But, accessing its StackTrace
itself threw an exception with the following stack trace:
System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)\r\n at
System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()\r\n at
System.Reflection.RuntimeMethodInfo.GetParameters()\r\n at
System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)\r\n at
System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)\r\n at
System.Exception.GetStackTrace(Boolean needFileInfo)\r\n at
System.Exception.get_StackTrace()