18 internal enum TraceFormat
27 private int m_iNumOfFrames;
32 private int m_iMethodsToSkip;
43 CaptureStackTrace(0, fNeedFileInfo:
false,
null,
null);
53 CaptureStackTrace(0, fNeedFileInfo,
null,
null);
67 CaptureStackTrace(skipFrames + 0, fNeedFileInfo:
false,
null,
null);
83 CaptureStackTrace(skipFrames + 0, fNeedFileInfo,
null,
null);
97 CaptureStackTrace(0, fNeedFileInfo:
false,
null, e);
112 m_iMethodsToSkip = 0;
113 CaptureStackTrace(0, fNeedFileInfo,
null, e);
132 m_iMethodsToSkip = 0;
133 CaptureStackTrace(skipFrames + 0, fNeedFileInfo:
false,
null, e);
154 m_iMethodsToSkip = 0;
155 CaptureStackTrace(skipFrames + 0, fNeedFileInfo,
null, e);
164 m_iMethodsToSkip = 0;
173 [Obsolete(
"This constructor has been deprecated. Please use a constructor that does not require a Thread parameter. http://go.microsoft.com/fwlink/?linkid=14202")]
177 m_iMethodsToSkip = 0;
178 CaptureStackTrace(0, needFileInfo, targetThread,
null);
182 [SecuritySafeCritical]
183 internal static extern void GetStackFramesInternal(StackFrameHelper sfh,
int iSkip,
bool fNeedFileInfo,
Exception e);
185 internal static int CalculateFramesToSkip(StackFrameHelper StackF,
int iNumFrames)
188 string strB =
"System.Diagnostics";
189 for (
int i = 0; i < iNumFrames; i++)
191 MethodBase methodBase = StackF.GetMethodBase(i);
192 if (methodBase !=
null)
195 if (declaringType ==
null)
199 string @
namespace = declaringType.Namespace;
200 if (@
namespace ==
null ||
string.Compare(@
namespace, strB,
StringComparison.Ordinal) != 0)
210 private void CaptureStackTrace(
int iSkip,
bool fNeedFileInfo,
Thread targetThread, Exception e)
212 m_iMethodsToSkip += iSkip;
213 using (StackFrameHelper stackFrameHelper =
new StackFrameHelper(targetThread))
215 stackFrameHelper.InitializeSourceInfo(0, fNeedFileInfo, e);
216 m_iNumOfFrames = stackFrameHelper.GetNumberOfFrames();
217 if (m_iMethodsToSkip > m_iNumOfFrames)
219 m_iMethodsToSkip = m_iNumOfFrames;
221 if (m_iNumOfFrames != 0)
223 frames =
new StackFrame[m_iNumOfFrames];
224 for (
int i = 0; i < m_iNumOfFrames; i++)
226 bool dummyFlag =
true;
227 bool dummyFlag2 =
true;
228 StackFrame stackFrame =
new StackFrame(dummyFlag, dummyFlag2);
229 stackFrame.SetMethodBase(stackFrameHelper.GetMethodBase(i));
230 stackFrame.SetOffset(stackFrameHelper.GetOffset(i));
231 stackFrame.SetILOffset(stackFrameHelper.GetILOffset(i));
232 stackFrame.SetIsLastFrameFromForeignExceptionStackTrace(stackFrameHelper.IsLastFrameFromForeignExceptionStackTrace(i));
235 stackFrame.SetFileName(stackFrameHelper.GetFilename(i));
236 stackFrame.SetLineNumber(stackFrameHelper.GetLineNumber(i));
237 stackFrame.SetColumnNumber(stackFrameHelper.GetColumnNumber(i));
239 frames[i] = stackFrame;
243 m_iMethodsToSkip += CalculateFramesToSkip(stackFrameHelper, m_iNumOfFrames);
245 m_iNumOfFrames -= m_iMethodsToSkip;
246 if (m_iNumOfFrames < 0)
263 if (frames !=
null && index < m_iNumOfFrames && index >= 0)
265 return frames[index + m_iMethodsToSkip];
275 if (frames ==
null || m_iNumOfFrames <= 0)
280 Array.
Copy(frames, m_iMethodsToSkip, array, 0, m_iNumOfFrames);
288 return ToString(TraceFormat.TrailingNewLine);
291 internal string ToString(TraceFormat traceFormat)
295 string format =
"in {0}:line {1}";
296 if (traceFormat != TraceFormat.NoResourceLookup)
299 format =
Environment.GetResourceString(
"StackTrace_InFileLineNumber");
303 for (
int i = 0; i < m_iNumOfFrames; i++)
307 if (!(method !=
null))
317 stringBuilder.
Append(Environment.NewLine);
321 if (declaringType !=
null)
323 stringBuilder.
Append(declaringType.FullName.Replace(
'+',
'.'));
324 stringBuilder.
Append(
".");
329 Type[] genericArguments = ((
MethodInfo)method).GetGenericArguments();
330 stringBuilder.
Append(
"[");
333 for (; j < genericArguments.Length; j++)
337 stringBuilder.
Append(
",");
343 stringBuilder.
Append(genericArguments[j].Name);
345 stringBuilder.
Append(
"]");
347 stringBuilder.
Append(
"(");
350 for (
int k = 0; k < parameters.Length; k++)
354 stringBuilder.
Append(
", ");
360 string str =
"<UnknownType>";
361 if (parameters[k].ParameterType !=
null)
365 stringBuilder.
Append(str +
" " + parameters[k].Name);
367 stringBuilder.
Append(
")");
368 if (flag && frame.GetILOffset() != -1)
373 text = frame.GetFileName();
375 catch (NotSupportedException)
385 stringBuilder.
Append(
' ');
389 if (frame.GetIsLastFrameFromForeignExceptionStackTrace())
391 stringBuilder.
Append(Environment.NewLine);
392 stringBuilder.
Append(Environment.GetResourceString(
"Exception_EndStackTraceFromPreviousThrow"));
395 if (traceFormat == TraceFormat.TrailingNewLine)
397 stringBuilder.
Append(Environment.NewLine);
402 private static string GetManagedStackTraceStringHelper(
bool fNeedFileInfo)
405 return stackTrace.ToString();
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Discovers the attributes of a parameter and provides access to parameter metadata.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
StackTrace()
Initializes a new instance of the T:System.Diagnostics.StackTrace class from the caller's frame.
abstract Type DeclaringType
Gets the class that declares this member.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
const int METHODS_TO_SKIP
Defines the default for the number of methods to omit from the stack trace. This field is constant.
Discovers the attributes of a method and provides access to method metadata.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
Represents a stack trace, which is an ordered collection of one or more stack frames.
virtual int FrameCount
Gets the number of frames in the stack trace.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
StackTrace(StackFrame frame)
Initializes a new instance of the T:System.Diagnostics.StackTrace class that contains a single frame.
StackTrace(Exception e, int skipFrames, bool fNeedFileInfo)
Initializes a new instance of the T:System.Diagnostics.StackTrace class using the provided exception ...
virtual StackFrame [] GetFrames()
Returns a copy of all stack frames in the current stack trace.
StackTrace(int skipFrames)
Initializes a new instance of the T:System.Diagnostics.StackTrace class from the caller's frame,...
StackTrace(int skipFrames, bool fNeedFileInfo)
Initializes a new instance of the T:System.Diagnostics.StackTrace class from the caller's frame,...
StringBuilder AppendFormat(string format, object arg0)
Appends the string returned by processing a composite format string, which contains zero or more form...
StackTrace(Exception e)
Initializes a new instance of the T:System.Diagnostics.StackTrace class using the provided exception ...
StackTrace(Exception e, int skipFrames)
Initializes a new instance of the T:System.Diagnostics.StackTrace class using the provided exception ...
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
override string ToString()
Builds a readable representation of the stack trace.
Represents type declarations: class types, interface types, array types, value types,...
StackTrace(Exception e, bool fNeedFileInfo)
Initializes a new instance of the T:System.Diagnostics.StackTrace class, using the provided exception...
Provides information about methods and constructors.
MethodImplOptions
Defines the details of how a method is implemented.
abstract string Name
Gets the name of the current member.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
StackTrace(Thread targetThread, bool needFileInfo)
Initializes a new instance of the T:System.Diagnostics.StackTrace class for a specific thread,...
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Specifies that the class can be serialized.
virtual Type ParameterType
Gets the Type of this parameter.
Provides information about a T:System.Diagnostics.StackFrame, which represents a function call on the...
Provides information about a specific culture (called a locale for unmanaged code development)....
The exception that is thrown when a security error is detected.
virtual StackFrame GetFrame(int index)
Gets the specified stack frame.
abstract ParameterInfo [] GetParameters()
When overridden in a derived class, gets the parameters of the specified method or constructor.
StackTrace(bool fNeedFileInfo)
Initializes a new instance of the T:System.Diagnostics.StackTrace class from the caller's frame,...
Creates and controls a thread, sets its priority, and gets its status.