dotnet / dotnet/aspnetcore

Backport #52687 to .NET8

Open
#55,892 0 comments 1 reaction 0 assignees View on GitHub
area-middleware feature-diagnostics
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Hi,

Please backport fix #52687 to .NET 8.

Some MudBlazor customers report (https://github.com/MudBlazor/MudBlazor/issues/7879) that they get exceptions when using:
```C#
app.UseExceptionHandler("/Error", createScopeForErrors: true);
```
or when they use Azure (https://github.com/MudBlazor/MudBlazor/discussions/8850).

The main problem is that our services added to the DI are implementing only `IAsyncDisposable`. We find this justified as we need to use some async code during disposal, and you can't use `GetAwaiter().GetResult()` in Blazor WASM. We also don't think that fire-and-forget is a good practice either.

I find that it's a bug in .NET 8 that it's calling `CreateScope` instead of `CreateAsyncScope`. Since it was fixed for .NET 9, it should be ported to .NET 8 as it's still supported. I don't see any breaking change risks here nor it doesn't require any new API.

Thank you.

### Expected Behavior

Not to throw exception.

### Steps To Reproduce

_No response_

### Exceptions (if any)

```
System.InvalidOperationException: 'MudBlazor.BrowserViewportService' type only implements IAsyncDisposable. Use DisposeAsync to dispose the container.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.Dispose()
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.HandleException(HttpContext context, ExceptionDispatchInfo edi)
```

### .NET Version

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.