-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Handle synchronous exceptions from partial #16679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.IO; | ||
using System.Text.Encodings.Web; | ||
using Microsoft.AspNetCore.Html; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
|
||
namespace TagHelpersWebSite | ||
{ | ||
public class MyHtmlContent : IHtmlContent | ||
{ | ||
private IHtmlHelper Html { get; } | ||
|
||
public MyHtmlContent(IHtmlHelper html) | ||
{ | ||
Html = html; | ||
} | ||
|
||
public void WriteTo(TextWriter writer, HtmlEncoder encoder) | ||
{ | ||
#pragma warning disable MVC1000 // Use of IHtmlHelper.{0} should be avoided. | ||
Html.Partial("_Test").WriteTo(writer, encoder); | ||
#pragma warning restore MVC1000 // Use of IHtmlHelper.{0} should be avoided. | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@(new TagHelpersWebSite.MyHtmlContent(Html)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The extra indirection seems to be necessary. Tested it out and we don't get the Synchronous complain otherwise. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@{ | ||
throw new Exception("Should be visible"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be fairly easy to write a unit test for this too. Basically we would write a test where the body of the view in https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.ViewFeatures/test/ViewExecutorTest.cs#L94-L97 throws and the test ensures that MVC does not perform a synchronous write to the HTTP response stream.