Beispiel #1
0
        [System.Security.SecurityCritical] // auto-generated
#endif
        internal String ToString(TraceFormat traceFormat)
        {
            bool   displayFilenames = true; // we'll try, but demand may fail
            String word_At          = "at";
            String inFileLineNum    = "in {0}:line {1}";

            if (traceFormat != TraceFormat.NoResourceLookup)
            {
                word_At       = Environment.GetResourceString("Word_At");
                inFileLineNum = Environment.GetResourceString("StackTrace_InFileLineNumber");
            }

            bool          fFirstFrame = true;
            StringBuilder sb          = new StringBuilder(255);

            for (int iFrameIndex = 0; iFrameIndex < m_iNumOfFrames; iFrameIndex++)
            {
                StackFrame sf = GetFrame(iFrameIndex);
                MethodBase mb = sf.GetMethod();
                if (mb != null)
                {
                    // We want a newline at the end of every line except for the last
                    if (fFirstFrame)
                    {
                        fFirstFrame = false;
                    }
                    else
                    {
                        sb.Append(Environment.NewLine);
                    }

                    sb.AppendFormat(CultureInfo.InvariantCulture, "   {0} ", word_At);

                    Type t = mb.DeclaringType;
                    // if there is a type (non global method) print it
                    if (t != null)
                    {
                        // Append t.FullName, replacing '+' with '.'
                        string fullName = t.FullName;
                        for (int i = 0; i < fullName.Length; i++)
                        {
                            char ch = fullName[i];
                            sb.Append(ch == '+' ? '.' : ch);
                        }
                        sb.Append('.');
                    }
                    sb.Append(mb.Name);

                    // deal with the generic portion of the method
                    if (mb is MethodInfo && ((MethodInfo)mb).IsGenericMethod)
                    {
                        Type[] typars = ((MethodInfo)mb).GetGenericArguments();
                        sb.Append('[');
                        int  k             = 0;
                        bool fFirstTyParam = true;
                        while (k < typars.Length)
                        {
                            if (fFirstTyParam == false)
                            {
                                sb.Append(',');
                            }
                            else
                            {
                                fFirstTyParam = false;
                            }

                            sb.Append(typars[k].Name);
                            k++;
                        }
                        sb.Append(']');
                    }

                    ParameterInfo[] pi = null;
#if FEATURE_CORECLR
                    try
                    {
#endif
                    pi = mb.GetParameters();
#if FEATURE_CORECLR
                }
                catch
                {
                    // The parameter info cannot be loaded, so we don't
                    // append the parameter list.
                }
#endif
                    if (pi != null)
                    {
                        // arguments printing
                        sb.Append('(');
                        bool fFirstParam = true;
                        for (int j = 0; j < pi.Length; j++)
                        {
                            if (fFirstParam == false)
                            {
                                sb.Append(", ");
                            }
                            else
                            {
                                fFirstParam = false;
                            }

                            String typeName = "<UnknownType>";
                            if (pi[j].ParameterType != null)
                            {
                                typeName = pi[j].ParameterType.Name;
                            }
                            sb.Append(typeName);
                            sb.Append(' ');
                            sb.Append(pi[j].Name);
                        }
                        sb.Append(')');
                    }

                    // source location printing
                    if (displayFilenames && (sf.GetILOffset() != -1))
                    {
                        // If we don't have a PDB or PDB-reading is disabled for the module,
                        // then the file name will be null.
                        String fileName = null;

                        // Getting the filename from a StackFrame is a privileged operation - we won't want
                        // to disclose full path names to arbitrarily untrusted code.  Rather than just omit
                        // this we could probably trim to just the filename so it's still mostly usefull.
                        try
                        {
                            fileName = sf.GetFileName();
                        }
                        catch (SecurityException)
                        {
                            // If the demand for displaying filenames fails, then it won't
                            // succeed later in the loop.  Avoid repeated exceptions by not trying again.
                            displayFilenames = false;
                        }

                        if (fileName != null)
                        {
                            // tack on " in c:\tmp\MyFile.cs:line 5"
                            sb.Append(' ');
                            sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber());
                        }
                    }

#if FEATURE_EXCEPTIONDISPATCHINFO
                    if (sf.GetIsLastFrameFromForeignExceptionStackTrace())
                    {
                        sb.Append(Environment.NewLine);
                        sb.Append(Environment.GetResourceString("Exception_EndStackTraceFromPreviousThrow"));
                    }
#endif // FEATURE_EXCEPTIONDISPATCHINFO
                }
            }

            if (traceFormat == TraceFormat.TrailingNewLine)
            {
                sb.Append(Environment.NewLine);
            }

            return(sb.ToString());
        }
Beispiel #2
0
        // Builds a readable representation of the stack trace, specifying
        // the format for backwards compatibility.
        internal string ToString(TraceFormat traceFormat)
        {
            bool   displayFilenames = true; // we'll try, but demand may fail
            string word_At          = "at";
            string inFileLineNum    = "in {0}:line {1}";

            if (traceFormat != TraceFormat.NoResourceLookup)
            {
                word_At       = SR.Word_At;
                inFileLineNum = SR.StackTrace_InFileLineNumber;
            }

            bool          fFirstFrame = true;
            StringBuilder sb          = new StringBuilder(255);

            for (int iFrameIndex = 0; iFrameIndex < m_iNumOfFrames; iFrameIndex++)
            {
                StackFrame sf = GetFrame(iFrameIndex);
                MethodBase mb = sf.GetMethod();
                if (mb != null && (ShowInStackTrace(mb) ||
                                   (iFrameIndex == m_iNumOfFrames - 1))) // Don't filter last frame
                {
                    // We want a newline at the end of every line except for the last
                    if (fFirstFrame)
                    {
                        fFirstFrame = false;
                    }
                    else
                    {
                        sb.Append(Environment.NewLine);
                    }

                    sb.AppendFormat(CultureInfo.InvariantCulture, "   {0} ", word_At);

                    bool   isAsync       = false;
                    Type   declaringType = mb.DeclaringType;
                    string methodName    = mb.Name;
                    bool   methodChanged = false;
                    if (declaringType != null && declaringType.IsDefined(typeof(CompilerGeneratedAttribute)))
                    {
                        isAsync = typeof(IAsyncStateMachine).IsAssignableFrom(declaringType);
                        if (isAsync || typeof(IEnumerator).IsAssignableFrom(declaringType))
                        {
                            methodChanged = TryResolveStateMachineMethod(ref mb, out declaringType);
                        }
                    }

                    // if there is a type (non global method) print it
                    // ResolveStateMachineMethod may have set declaringType to null
                    if (declaringType != null)
                    {
                        // Append t.FullName, replacing '+' with '.'
                        string fullName = declaringType.FullName;
                        for (int i = 0; i < fullName.Length; i++)
                        {
                            char ch = fullName[i];
                            sb.Append(ch == '+' ? '.' : ch);
                        }
                        sb.Append('.');
                    }
                    sb.Append(mb.Name);

                    // deal with the generic portion of the method
                    if (mb is MethodInfo && ((MethodInfo)mb).IsGenericMethod)
                    {
                        Type[] typars = ((MethodInfo)mb).GetGenericArguments();
                        sb.Append('[');
                        int  k             = 0;
                        bool fFirstTyParam = true;
                        while (k < typars.Length)
                        {
                            if (fFirstTyParam == false)
                            {
                                sb.Append(',');
                            }
                            else
                            {
                                fFirstTyParam = false;
                            }

                            sb.Append(typars[k].Name);
                            k++;
                        }
                        sb.Append(']');
                    }

                    ParameterInfo[] pi = null;
                    try
                    {
                        pi = mb.GetParameters();
                    }
                    catch
                    {
                        // The parameter info cannot be loaded, so we don't
                        // append the parameter list.
                    }
                    if (pi != null)
                    {
                        // arguments printing
                        sb.Append('(');
                        bool fFirstParam = true;
                        for (int j = 0; j < pi.Length; j++)
                        {
                            if (fFirstParam == false)
                            {
                                sb.Append(", ");
                            }
                            else
                            {
                                fFirstParam = false;
                            }

                            string typeName = "<UnknownType>";
                            if (pi[j].ParameterType != null)
                            {
                                typeName = pi[j].ParameterType.Name;
                            }
                            sb.Append(typeName);
                            sb.Append(' ');
                            sb.Append(pi[j].Name);
                        }
                        sb.Append(')');
                    }

                    if (methodChanged)
                    {
                        // Append original method name e.g. +MoveNext()
                        sb.Append("+");
                        sb.Append(methodName);
                        sb.Append("()");
                    }

                    // source location printing
                    if (displayFilenames && (sf.GetILOffset() != -1))
                    {
                        // If we don't have a PDB or PDB-reading is disabled for the module,
                        // then the file name will be null.
                        string fileName = null;

                        // Getting the filename from a StackFrame is a privileged operation - we won't want
                        // to disclose full path names to arbitrarily untrusted code.  Rather than just omit
                        // this we could probably trim to just the filename so it's still mostly usefull.
                        try
                        {
                            fileName = sf.GetFileName();
                        }
                        catch (SecurityException)
                        {
                            // If the demand for displaying filenames fails, then it won't
                            // succeed later in the loop.  Avoid repeated exceptions by not trying again.
                            displayFilenames = false;
                        }

                        if (fileName != null)
                        {
                            // tack on " in c:\tmp\MyFile.cs:line 5"
                            sb.Append(' ');
                            sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber());
                        }
                    }

                    if (sf.GetIsLastFrameFromForeignExceptionStackTrace() &&
                        !isAsync) // Skip EDI boundary for async
                    {
                        sb.Append(Environment.NewLine);
                        sb.Append(SR.Exception_EndStackTraceFromPreviousThrow);
                    }
                }
            }

            if (traceFormat == TraceFormat.TrailingNewLine)
            {
                sb.Append(Environment.NewLine);
            }

            return(sb.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// Builds a readable representation of the stack trace, specifying
        /// the format for backwards compatibility.
        /// </summary>
        internal string ToString(TraceFormat traceFormat)
        {
            string word_At       = SR.Word_At;
            string inFileLineNum = SR.StackTrace_InFileLineNumber;

            bool          fFirstFrame = true;
            StringBuilder sb          = new StringBuilder(255);

            for (int iFrameIndex = 0; iFrameIndex < _numOfFrames; iFrameIndex++)
            {
                StackFrame sf = GetFrame(iFrameIndex);
                MethodBase mb = sf.GetMethod();
                if (mb != null && (ShowInStackTrace(mb) ||
                                   (iFrameIndex == _numOfFrames - 1))) // Don't filter last frame
                {
                    // We want a newline at the end of every line except for the last
                    if (fFirstFrame)
                    {
                        fFirstFrame = false;
                    }
                    else
                    {
                        sb.Append(Environment.NewLine);
                    }

                    sb.AppendFormat(CultureInfo.InvariantCulture, "   {0} ", word_At);

                    bool   isAsync       = false;
                    Type   declaringType = mb.DeclaringType;
                    string methodName    = mb.Name;
                    bool   methodChanged = false;
                    if (declaringType != null && declaringType.IsDefined(typeof(CompilerGeneratedAttribute), inherit: false))
                    {
                        isAsync = typeof(IAsyncStateMachine).IsAssignableFrom(declaringType);
                        if (isAsync || typeof(IEnumerator).IsAssignableFrom(declaringType))
                        {
                            methodChanged = TryResolveStateMachineMethod(ref mb, out declaringType);
                        }
                    }

                    // if there is a type (non global method) print it
                    // ResolveStateMachineMethod may have set declaringType to null
                    if (declaringType != null)
                    {
                        // Append t.FullName, replacing '+' with '.'
                        string fullName = declaringType.FullName;
                        for (int i = 0; i < fullName.Length; i++)
                        {
                            char ch = fullName[i];
                            sb.Append(ch == '+' ? '.' : ch);
                        }
                        sb.Append('.');
                    }
                    sb.Append(mb.Name);

                    // deal with the generic portion of the method
                    if (mb is MethodInfo mi && mi.IsGenericMethod)
                    {
                        Type[] typars = mi.GetGenericArguments();
                        sb.Append('[');
                        int  k             = 0;
                        bool fFirstTyParam = true;
                        while (k < typars.Length)
                        {
                            if (fFirstTyParam == false)
                            {
                                sb.Append(',');
                            }
                            else
                            {
                                fFirstTyParam = false;
                            }

                            sb.Append(typars[k].Name);
                            k++;
                        }
                        sb.Append(']');
                    }

                    ParameterInfo[] pi = null;
                    try
                    {
                        pi = mb.GetParameters();
                    }
                    catch
                    {
                        // The parameter info cannot be loaded, so we don't
                        // append the parameter list.
                    }
                    if (pi != null)
                    {
                        // arguments printing
                        sb.Append('(');
                        bool fFirstParam = true;
                        for (int j = 0; j < pi.Length; j++)
                        {
                            if (fFirstParam == false)
                            {
                                sb.Append(", ");
                            }
                            else
                            {
                                fFirstParam = false;
                            }

                            string typeName = "<UnknownType>";
                            if (pi[j].ParameterType != null)
                            {
                                typeName = pi[j].ParameterType.Name;
                            }
                            sb.Append(typeName);
                            sb.Append(' ');
                            sb.Append(pi[j].Name);
                        }
                        sb.Append(')');
                    }

                    if (methodChanged)
                    {
                        // Append original method name e.g. +MoveNext()
                        sb.Append('+');
                        sb.Append(methodName);
                        sb.Append('(').Append(')');
                    }

                    // source location printing
                    if (sf.GetILOffset() != -1)
                    {
                        // If we don't have a PDB or PDB-reading is disabled for the module,
                        // then the file name will be null.
                        string fileName = sf.GetFileName();

                        if (fileName != null)
                        {
                            // tack on " in c:\tmp\MyFile.cs:line 5"
                            sb.Append(' ');
                            sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber());
                        }
                    }

                    if (sf.GetIsLastFrameFromForeignExceptionStackTrace() &&
                        !isAsync) // Skip EDI boundary for async
                    {
                        sb.Append(Environment.NewLine);
                        sb.Append(SR.Exception_EndStackTraceFromPreviousThrow);
                    }
                }
            }

            if (traceFormat == TraceFormat.TrailingNewLine)
            {
                sb.Append(Environment.NewLine);
            }

            return(sb.ToString());
        }
        // Token: 0x0600325C RID: 12892 RVA: 0x000C1298 File Offset: 0x000BF498
        internal string ToString(StackTrace.TraceFormat traceFormat)
        {
            bool   flag   = true;
            string arg    = "at";
            string format = "in {0}:line {1}";

            if (traceFormat != StackTrace.TraceFormat.NoResourceLookup)
            {
                arg    = Environment.GetResourceString("Word_At");
                format = Environment.GetResourceString("StackTrace_InFileLineNumber");
            }
            bool          flag2         = true;
            StringBuilder stringBuilder = new StringBuilder(255);

            for (int i = 0; i < this.m_iNumOfFrames; i++)
            {
                StackFrame frame  = this.GetFrame(i);
                MethodBase method = frame.GetMethod();
                if (method != null)
                {
                    if (flag2)
                    {
                        flag2 = false;
                    }
                    else
                    {
                        stringBuilder.Append(Environment.NewLine);
                    }
                    stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "   {0} ", arg);
                    Type declaringType = method.DeclaringType;
                    if (declaringType != null)
                    {
                        stringBuilder.Append(declaringType.FullName.Replace('+', '.'));
                        stringBuilder.Append(".");
                    }
                    stringBuilder.Append(method.Name);
                    if (method is MethodInfo && ((MethodInfo)method).IsGenericMethod)
                    {
                        Type[] genericArguments = ((MethodInfo)method).GetGenericArguments();
                        stringBuilder.Append("[");
                        int  j     = 0;
                        bool flag3 = true;
                        while (j < genericArguments.Length)
                        {
                            if (!flag3)
                            {
                                stringBuilder.Append(",");
                            }
                            else
                            {
                                flag3 = false;
                            }
                            stringBuilder.Append(genericArguments[j].Name);
                            j++;
                        }
                        stringBuilder.Append("]");
                    }
                    stringBuilder.Append("(");
                    ParameterInfo[] parameters = method.GetParameters();
                    bool            flag4      = true;
                    for (int k = 0; k < parameters.Length; k++)
                    {
                        if (!flag4)
                        {
                            stringBuilder.Append(", ");
                        }
                        else
                        {
                            flag4 = false;
                        }
                        string str = "<UnknownType>";
                        if (parameters[k].ParameterType != null)
                        {
                            str = parameters[k].ParameterType.Name;
                        }
                        stringBuilder.Append(str + " " + parameters[k].Name);
                    }
                    stringBuilder.Append(")");
                    if (flag && frame.GetILOffset() != -1)
                    {
                        string text = null;
                        try
                        {
                            text = frame.GetFileName();
                        }
                        catch (NotSupportedException)
                        {
                            flag = false;
                        }
                        catch (SecurityException)
                        {
                            flag = false;
                        }
                        if (text != null)
                        {
                            stringBuilder.Append(' ');
                            stringBuilder.AppendFormat(CultureInfo.InvariantCulture, format, text, frame.GetFileLineNumber());
                        }
                    }
                    if (frame.GetIsLastFrameFromForeignExceptionStackTrace())
                    {
                        stringBuilder.Append(Environment.NewLine);
                        stringBuilder.Append(Environment.GetResourceString("Exception_EndStackTraceFromPreviousThrow"));
                    }
                }
            }
            if (traceFormat == StackTrace.TraceFormat.TrailingNewLine)
            {
                stringBuilder.Append(Environment.NewLine);
            }
            return(stringBuilder.ToString());
        }
Beispiel #5
0
        internal string ToString(StackTrace.TraceFormat traceFormat)
        {
            bool   flag1  = true;
            string str1   = "at";
            string format = "in {0}:line {1}";

            if (traceFormat != StackTrace.TraceFormat.NoResourceLookup)
            {
                str1   = Environment.GetResourceString("Word_At");
                format = Environment.GetResourceString("StackTrace_InFileLineNumber");
            }
            bool          flag2         = true;
            StringBuilder stringBuilder = new StringBuilder((int)byte.MaxValue);

            for (int index1 = 0; index1 < this.m_iNumOfFrames; ++index1)
            {
                StackFrame frame  = this.GetFrame(index1);
                MethodBase method = frame.GetMethod();
                if (method != (MethodBase)null)
                {
                    if (flag2)
                    {
                        flag2 = false;
                    }
                    else
                    {
                        stringBuilder.Append(Environment.NewLine);
                    }
                    stringBuilder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, "   {0} ", (object)str1);
                    Type declaringType = method.DeclaringType;
                    if (declaringType != (Type)null)
                    {
                        stringBuilder.Append(declaringType.FullName.Replace('+', '.'));
                        stringBuilder.Append(".");
                    }
                    stringBuilder.Append(method.Name);
                    if (method is MethodInfo && method.IsGenericMethod)
                    {
                        Type[] genericArguments = method.GetGenericArguments();
                        stringBuilder.Append("[");
                        int  index2 = 0;
                        bool flag3  = true;
                        for (; index2 < genericArguments.Length; ++index2)
                        {
                            if (!flag3)
                            {
                                stringBuilder.Append(",");
                            }
                            else
                            {
                                flag3 = false;
                            }
                            stringBuilder.Append(genericArguments[index2].Name);
                        }
                        stringBuilder.Append("]");
                    }
                    stringBuilder.Append("(");
                    ParameterInfo[] parameters = method.GetParameters();
                    bool            flag4      = true;
                    for (int index2 = 0; index2 < parameters.Length; ++index2)
                    {
                        if (!flag4)
                        {
                            stringBuilder.Append(", ");
                        }
                        else
                        {
                            flag4 = false;
                        }
                        string str2 = "<UnknownType>";
                        if (parameters[index2].ParameterType != (Type)null)
                        {
                            str2 = parameters[index2].ParameterType.Name;
                        }
                        stringBuilder.Append(str2 + " " + parameters[index2].Name);
                    }
                    stringBuilder.Append(")");
                    if (flag1 && frame.GetILOffset() != -1)
                    {
                        string str2 = (string)null;
                        try
                        {
                            str2 = frame.GetFileName();
                        }
                        catch (NotSupportedException ex)
                        {
                            flag1 = false;
                        }
                        catch (SecurityException ex)
                        {
                            flag1 = false;
                        }
                        if (str2 != null)
                        {
                            stringBuilder.Append(' ');
                            stringBuilder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, format, (object)str2, (object)frame.GetFileLineNumber());
                        }
                    }
                    if (frame.GetIsLastFrameFromForeignExceptionStackTrace())
                    {
                        stringBuilder.Append(Environment.NewLine);
                        stringBuilder.Append(Environment.GetResourceString("Exception_EndStackTraceFromPreviousThrow"));
                    }
                }
            }
            if (traceFormat == StackTrace.TraceFormat.TrailingNewLine)
            {
                stringBuilder.Append(Environment.NewLine);
            }
            return(stringBuilder.ToString());
        }