Creating an issue based on convo from https://github.com/aspnet/AspNetCore/issues/7644#issuecomment-545540326 @NTaylorMullen. We have a library for rendering grids using a custom IHtmlContent implementation, which renders a partial after building a model for it, similar to this
```C#
public class MyHtmlContent : IHtmlContent
{
private IHtmlHelper Html { get; }
public MyHtmlContent(IHtmlHelper html)
{
Html = html;
}
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
{
Html.Partial("_Grid", BuildModel()).WriteTo(writer, encoder);
}
}
What happened was that an exception was thrown in the `_Grid` partial but it got consumed by invalid operation exception from [HttpResponseStream](https://github.com/aspnet/AspNetCore/blob/v3.0.0/src/Servers/IIS/IIS/src/Core/HttpResponseStream.cs#L41) and invalid operation exception is shown instead.
Calling `Html.Partial` directly from the view or not having exceptions in the `_Grid` partial doesn't show `Synchronous operations are disallowed` exception, suggesting that exception handling is using synchronous IO?
### To Reproduce
1. Clone [repro (expired)](https://github.com/Muchiachio/AsyncHtmlContentIO)
2. Run
3. You will see synchronous operations are not allowed exception.
### Expected behavior
Exception from `_TestPartial` being output to the screen.
### Additional context
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk3.0.100\
Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33
.NET Core SDKs installed:
3.0.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
```
In ASP.NET Core 3.0 version you're not allowed to use synchronous IO APIs as default, you could disable it by following configuration:
```c#
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(options =>
{
options.AllowSynchronousIO = true;
});
webBuilder.UseStartup<Startup>();
});
```
_But it's not recommended to use synchronous IO APIs._
Problem is not about using sync IO, the problem is that it's being triggered by exception only.
You can even use Html.Partial perfectly fine it doesn't throw async exceptions in the repro I provided.
@Muchiachio thanks for contacting us.
@pranavkm Would you be a good person to look at this?
@ryanbrandenburg we discussed this offline and I think the bug's here: https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.ViewFeatures/src/ViewExecutor.cs#L236-L260. Essentially if https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.ViewFeatures/src/ViewExecutor.cs#L247 throws, we end up calling a synchronous Dispose as a result of this using - https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.ViewFeatures/src/ViewExecutor.cs#L236.
My guess is that changing the using to await using is likely going to suffice. Would you want to investigate this further? There might be other places in MVC which have the same problem.
Most helpful comment
Problem is not about using sync IO, the problem is that it's being triggered by exception only.
You can even use
Html.Partialperfectly fine it doesn't throw async exceptions in the repro I provided.