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
Verification fails with IAsyncDisposable registrations #873
Comments
bug-873 branch created. |
This appears to be back in 5.4. This was discussed in the past here in the aspnetcore repo also: dotnet/aspnetcore#12918 |
@mkostreba, your bug report is similar to the previous report, but has a different cause. It's, therefore, a different bug. I moved this to issue 35 of the appropriate repository. You can follow the bug's status there. |
See issue 35 for a solution to this problem. |
Thank you for your prompt response!
|
To reproduce:
Verify fails with the following exception:
Context:
Solution
There are a few possible solutions:
VerifyAsync()
method and throw an expressive exception in caseVerify()
is called with IAsyncDisposable registrationsVerify()
dispose theIAsyncDisposable
services synchronously by calling.GetAwaiter().GetResult()
.Verify()
to operate in the current active scope (if any), instead of using its own scope. This prevents verify from having to callScope.Dispose()
, because disposal will be done later on.Downsides of each solutions:
Verify
is during the first call toGetInstance
. Get instance is not, and cannot become async andVerify()
is often called from startup code that is not, and cannot, become asynchronous (e.g. ASP.NET startup code).Our best bet is option 4. Although tracked components stay needlessly in memory, most applications will only have a handful of scoped components that will stay referenced. The risk is, therefore, low.
The text was updated successfully, but these errors were encountered: