Use Microsoft.Extensions.StackTrace.Sources
This commit is contained in:
parent
a3b2a7b62b
commit
d02f67785f
|
|
@ -8,12 +8,12 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using Microsoft.Extensions.Internal;
|
using Microsoft.Extensions.Internal;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
|
using Microsoft.Extensions.StackTrace.Sources;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Hosting
|
namespace Microsoft.AspNetCore.Hosting
|
||||||
{
|
{
|
||||||
|
|
@ -54,12 +54,12 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
return Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, _errorPageFormatString, builder, rawExceptionDetails, footer));
|
return Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, _errorPageFormatString, builder, rawExceptionDetails, footer));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string BuildCodeSnippetDiv(StackFrame frame)
|
private static string BuildCodeSnippetDiv(StackFrameInfo frameInfo)
|
||||||
{
|
{
|
||||||
var filename = frame.GetFileName();
|
var filename = frameInfo.FilePath;
|
||||||
if (!string.IsNullOrEmpty(filename))
|
if (!string.IsNullOrEmpty(filename))
|
||||||
{
|
{
|
||||||
int failingLineNumber = frame.GetFileLineNumber();
|
int failingLineNumber = frameInfo.LineNumber;
|
||||||
if (failingLineNumber >= 1)
|
if (failingLineNumber >= 1)
|
||||||
{
|
{
|
||||||
var lines = GetFailingCallSiteInFile(filename, failingLineNumber);
|
var lines = GetFailingCallSiteInFile(filename, failingLineNumber);
|
||||||
|
|
@ -76,10 +76,11 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string BuildLineForStackFrame(StackFrame frame)
|
private static string BuildLineForStackFrame(StackFrameInfo frameInfo)
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder("<pre>");
|
var builder = new StringBuilder("<pre>");
|
||||||
var method = frame.GetMethod();
|
var stackFrame = frameInfo.StackFrame;
|
||||||
|
var method = stackFrame.GetMethod();
|
||||||
|
|
||||||
// Special case: no method available
|
// Special case: no method available
|
||||||
if (method == null)
|
if (method == null)
|
||||||
|
|
@ -116,12 +117,12 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
builder.AppendFormat(CultureInfo.InvariantCulture, @"<span class=""faded"">{0}</span>", HtmlEncodeAndReplaceLineBreaks(BuildMethodParametersUnescaped(method)));
|
builder.AppendFormat(CultureInfo.InvariantCulture, @"<span class=""faded"">{0}</span>", HtmlEncodeAndReplaceLineBreaks(BuildMethodParametersUnescaped(method)));
|
||||||
|
|
||||||
// Do we have source information for this frame?
|
// Do we have source information for this frame?
|
||||||
if (frame.GetILOffset() != -1)
|
if (stackFrame.GetILOffset() != -1)
|
||||||
{
|
{
|
||||||
var filename = frame.GetFileName();
|
var filename = frameInfo.FilePath;
|
||||||
if (!string.IsNullOrEmpty(filename))
|
if (!string.IsNullOrEmpty(filename))
|
||||||
{
|
{
|
||||||
builder.AppendFormat(CultureInfo.InvariantCulture, " in {0}:line {1:D}", HtmlEncodeAndReplaceLineBreaks(filename), frame.GetFileLineNumber());
|
builder.AppendFormat(CultureInfo.InvariantCulture, " in {0}:line {1:D}", HtmlEncodeAndReplaceLineBreaks(filename), frameInfo.LineNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -235,7 +236,7 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
var environment = PlatformServices.Default.Runtime;
|
var environment = PlatformServices.Default.Runtime;
|
||||||
var runtimeType = HtmlEncodeAndReplaceLineBreaks(environment.RuntimeType);
|
var runtimeType = HtmlEncodeAndReplaceLineBreaks(environment.RuntimeType);
|
||||||
var runtimeDisplayName = runtimeType == "CoreCLR" ? ".NET Core" : runtimeType == "CLR" ? ".NET Framework" : "Mono";
|
var runtimeDisplayName = runtimeType == "CoreCLR" ? ".NET Core" : runtimeType == "CLR" ? ".NET Framework" : "Mono";
|
||||||
#if NETCOREAPP1_0 || NETSTANDARD1_3
|
#if NETSTANDARD1_5
|
||||||
var systemRuntimeAssembly = typeof(System.ComponentModel.DefaultValueAttribute).GetTypeInfo().Assembly;
|
var systemRuntimeAssembly = typeof(System.ComponentModel.DefaultValueAttribute).GetTypeInfo().Assembly;
|
||||||
var assemblyVersion = new AssemblyName(systemRuntimeAssembly.FullName).Version.ToString();
|
var assemblyVersion = new AssemblyName(systemRuntimeAssembly.FullName).Version.ToString();
|
||||||
var clrVersion = HtmlEncodeAndReplaceLineBreaks(assemblyVersion);
|
var clrVersion = HtmlEncodeAndReplaceLineBreaks(assemblyVersion);
|
||||||
|
|
@ -276,21 +277,20 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
// First, build the stack trace
|
// First, build the stack trace
|
||||||
var firstStackFrame = true;
|
var firstStackFrame = true;
|
||||||
var stackTraceBuilder = new StringBuilder();
|
var stackTraceBuilder = new StringBuilder();
|
||||||
var needFileInfo = true;
|
foreach (var frameInfo in StackTraceHelper.GetFrames(ex))
|
||||||
foreach (var frame in new StackTrace(ex, needFileInfo).GetFrames() ?? Enumerable.Empty<StackFrame>())
|
|
||||||
{
|
{
|
||||||
if (!firstStackFrame)
|
if (!firstStackFrame)
|
||||||
{
|
{
|
||||||
stackTraceBuilder.Append("<br />");
|
stackTraceBuilder.Append("<br />");
|
||||||
}
|
}
|
||||||
firstStackFrame = false;
|
firstStackFrame = false;
|
||||||
var thisFrameLine = BuildLineForStackFrame(frame);
|
var thisFrameLine = BuildLineForStackFrame(frameInfo);
|
||||||
stackTraceBuilder.AppendLine(thisFrameLine);
|
stackTraceBuilder.AppendLine(thisFrameLine);
|
||||||
|
|
||||||
// Try to include the source code in the error page if we can.
|
// Try to include the source code in the error page if we can.
|
||||||
if (!wasFailingCallSiteSourceWritten && inlineSourceDiv == null)
|
if (!wasFailingCallSiteSourceWritten && inlineSourceDiv == null)
|
||||||
{
|
{
|
||||||
inlineSourceDiv = BuildCodeSnippetDiv(frame);
|
inlineSourceDiv = BuildCodeSnippetDiv(frameInfo);
|
||||||
if (inlineSourceDiv != null)
|
if (inlineSourceDiv != null)
|
||||||
{
|
{
|
||||||
wasFailingCallSiteSourceWritten = true;
|
wasFailingCallSiteSourceWritten = true;
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,16 @@
|
||||||
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Logging": "1.0.0-*",
|
"Microsoft.Extensions.Logging": "1.0.0-*",
|
||||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
|
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
|
||||||
|
"Microsoft.Extensions.StackTrace.Sources": {
|
||||||
|
"type": "build",
|
||||||
|
"version": "1.0.0-*"
|
||||||
|
},
|
||||||
"Microsoft.Extensions.TypeNameHelper.Sources": {
|
"Microsoft.Extensions.TypeNameHelper.Sources": {
|
||||||
"version": "1.0.0-*",
|
"version": "1.0.0-*",
|
||||||
"type": "build"
|
"type": "build"
|
||||||
},
|
},
|
||||||
"System.Diagnostics.DiagnosticSource": "4.0.0-*"
|
"System.Diagnostics.DiagnosticSource": "4.0.0-*",
|
||||||
|
"System.Reflection.Metadata": "1.3.0-*"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net451": {
|
"net451": {
|
||||||
|
|
@ -50,7 +55,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"netstandard1.3": {
|
"netstandard1.5": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"System.Console": "4.0.0-*",
|
"System.Console": "4.0.0-*",
|
||||||
"System.Diagnostics.StackTrace": "4.0.1-*",
|
"System.Diagnostics.StackTrace": "4.0.1-*",
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
"System.Net.Http": ""
|
"System.Net.Http": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"netstandard1.3": {
|
"netstandard1.5": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"System.Diagnostics.Contracts": "4.0.1-*",
|
"System.Diagnostics.Contracts": "4.0.1-*",
|
||||||
"System.Net.Http": "4.1.0-*"
|
"System.Net.Http": "4.1.0-*"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue