Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
/MvcPublic archive

Commit8c8fd64

Browse files
committed
Use regular PDBs on full desktop when possible
Add a test to verify exceptions thrown from views is pretty printed by diagnostics middlewareFixesaspnet/Diagnostics#293Fixes#4737
1 parenta8142b8 commit8c8fd64

File tree

5 files changed

+90
-13
lines changed

5 files changed

+90
-13
lines changed

‎src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRoslynCompilationService.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
2727
/// </summary>
2828
publicclassDefaultRoslynCompilationService:ICompilationService
2929
{
30+
privatereadonlyDebugInformationFormat_pdbFormat=SymbolsUtility.SupportsFullPdbGeneration()?
31+
DebugInformationFormat.Pdb:
32+
DebugInformationFormat.PortablePdb;
3033
privatereadonlyApplicationPartManager_partManager;
3134
privatereadonlyIFileProvider_fileProvider;
3235
privatereadonlyAction<RoslynCompilationContext>_compilationCallback;
@@ -116,7 +119,7 @@ public CompilationResult Compile(RelativeFileInfo fileInfo, string compilationCo
116119
varresult=compilation.Emit(
117120
assemblyStream,
118121
pdbStream,
119-
options:newEmitOptions(debugInformationFormat:DebugInformationFormat.PortablePdb));
122+
options:newEmitOptions(debugInformationFormat:_pdbFormat));
120123

121124
if(!result.Success)
122125
{
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
usingSystem;
5+
usingSystem.Runtime.InteropServices;
6+
7+
namespaceMicrosoft.AspNetCore.Mvc.Razor.Internal
8+
{
9+
/// <summary>
10+
/// Utility type for determining if a platform supports full pdb file generation.
11+
/// </summary>
12+
publicclassSymbolsUtility
13+
{
14+
privateconststringSymWriterGuid="0AE2DEB0-F901-478b-BB9F-881EE8066788";
15+
16+
/// <summary>
17+
/// Determines if the current platform supports full pdb generation.
18+
/// </summary>
19+
/// <returns><c>true</c> if full pdb generation is supported; <c>false</c> otherwise.</returns>
20+
publicstaticboolSupportsFullPdbGeneration()
21+
{
22+
if(Type.GetType("Mono.Runtime")!=null)
23+
{
24+
returnfalse;
25+
}
26+
27+
try
28+
{
29+
// Check for the pdb writer component that roslyn uses to generate pdbs
30+
vartype=Marshal.GetTypeFromCLSID(newGuid(SymWriterGuid));
31+
if(type!=null)
32+
{
33+
// This line will throw if pdb generation is not supported.
34+
Activator.CreateInstance(type);
35+
returntrue;
36+
}
37+
}
38+
catch
39+
{
40+
}
41+
42+
returnfalse;
43+
}
44+
}
45+
}

‎test/Microsoft.AspNetCore.Mvc.FunctionalTests/ErrorPageTests.cs‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
usingSystem.Net;
55
usingSystem.Net.Http;
66
usingSystem.Net.Http.Headers;
7+
usingSystem.Text.Encodings.Web;
78
usingSystem.Threading.Tasks;
8-
#if!NETCOREAPP1_0
9-
usingMicrosoft.AspNetCore.Testing.xunit;
10-
#endif
9+
usingMicrosoft.AspNetCore.Mvc.Razor.Internal;
1110
usingXunit;
1211

1312
namespaceMicrosoft.AspNetCore.Mvc.FunctionalTests
@@ -24,17 +23,13 @@ public ErrorPageTests(MvcTestFixture<ErrorPageMiddlewareWebSite.Startup> fixture
2423

2524
publicHttpClientClient{get;}
2625

27-
#ifNETCOREAPP1_0
2826
[Theory]
29-
#else
30-
[ConditionalTheory]
31-
[OSSkipCondition(OperatingSystems.MacOSX,SkipReason="aspnet/Mvc#3587")]
32-
#endif
3327
[InlineData("CompilationFailure","Cannot implicitly convert type &#x27;int&#x27; to &#x27;string&#x27;")]
34-
[InlineData("ParserError","The code block is missing a closing &quot;}&quot; character. Make sure you "+
35-
"have a matching &quot;}&quot; character for all the &quot;{&quot; characters "+
36-
"within this block, and that none of the &quot;}&quot; characters are being "+
37-
"interpreted as markup.")]
28+
[InlineData("ParserError",
29+
"The code block is missing a closing &quot;}&quot; character. Make sure you "+
30+
"have a matching &quot;}&quot; character for all the &quot;{&quot; characters "+
31+
"within this block, and that none of the &quot;}&quot; characters are being "+
32+
"interpreted as markup.")]
3833
publicasyncTaskCompilationFailuresAreListedByErrorPageMiddleware(stringaction,stringexpected)
3934
{
4035
// Arrange
@@ -69,5 +64,33 @@ public async Task CompilationFailuresFromViewImportsAreListed()
6964
Assert.Contains("/Views/ErrorFromViewImports/_ViewImports.cshtml",content);
7065
Assert.Contains(expectedMessage,content);
7166
}
67+
68+
[Fact]
69+
publicasyncTaskRuntimeErrorAreListedByErrorPageMiddleware()
70+
{
71+
// The desktop CLR does not correctly read the stack trace from portable PDBs. However generating full pdbs
72+
// is only supported on machines with CLSID_CorSymWriter available. On desktop, we'll skip this test on
73+
// machines without this component.
74+
#ifNET451
75+
if(!SymbolsUtility.SupportsFullPdbGeneration())
76+
{
77+
return;
78+
}
79+
#endif
80+
81+
// Arrange
82+
varexpectedMessage=HtmlEncoder.Default.Encode("throw new Exception(\"Error from view\");");
83+
varexpectedMediaType=MediaTypeHeaderValue.Parse("text/html; charset=utf-8");
84+
85+
// Act
86+
varresponse=awaitClient.GetAsync("http://localhost/RuntimeError");
87+
88+
// Assert
89+
Assert.Equal(HttpStatusCode.InternalServerError,response.StatusCode);
90+
Assert.Equal(expectedMediaType,response.Content.Headers.ContentType);
91+
varcontent=awaitresponse.Content.ReadAsStringAsync();
92+
Assert.Contains("/Views/ErrorPageMiddleware/RuntimeError.cshtml",content);
93+
Assert.Contains(expectedMessage,content);
94+
}
7295
}
7396
}

‎test/WebSites/ErrorPageMiddlewareWebSite/ErrorPageMiddlewareController.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@ public IActionResult ViewImportsError()
2424
{
2525
returnView("~/Views/ErrorFromViewImports/Index.cshtml");
2626
}
27+
28+
[HttpGet("/RuntimeError")]
29+
publicIActionResultRuntimeError()=>View();
2730
}
2831
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
thrownewException("Error from view");
3+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp