[Blazor server-side] OwningComponentBase disposed inside OnParametersSetAsync during Login/Logout
See original GitHub issueDescribe the bug
I have custom authentication provider to provide refresh-less login/logout. If I login/logout on page inheriting OwningComponentBase then I get System.ObjectDisposedException
To Reproduce
Not so sure about reproducing steps but mine steps are:
- Going to page with child component having OwningComponentBase
- Login/Logout
- Receive System.ObjectDisposedException
Got Exceptions? Include both the message and the stack trace
blazor.server.js:15 [2020-04-08T17:04:44.371Z] Error: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Category'.
at Microsoft.AspNetCore.Components.OwningComponentBase`1.get_Service()
at Shople.Shared.Category.OnParametersSetAsync() in F:\ASP.NET Core\Shople\src\Shared\Category.razor:line 355
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
Component::OnParametersSetAsync (component implement IDisposable)
protected override async Task OnParametersSetAsync()
{
Products = null;
FilterItems = await Service?.GetCategoryFiltersAsync(Model.Category.Id); // OK, NO EXCEPTION
StateHasChanged();
Products = (await Service?.GetCategoryProductsAsync(Model.Category.Id, DisplayOrder, Page)).DiscountList((await AuthenticationStateTask).User); // EXCEPTION, Service is disposed... LINE 355
}
Further technical details
- ASP.NET Core version 3.1.2
- VS 16.5
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ASP.NET Core Blazor dependency injection
After the request completes, any scoped or transient services are disposed by the DI system. Server-side, the request scope lasts for the ...
Read more >Why are Blazor lifecycle methods getting executed twice?
Try replacing RenderMode.ServerPrerendered with RenderMode.Server , then it behaves as expected, which is that the lifecycle methods are only ...
Read more >An Introduction to OwningComponentBase
In this post, I'm going to explore the new OwningComponentBase class. I'll look at the quirks of service scopes in Blazor and how...
Read more >Blazor Server: Cannot access a disposed object.
In a Blazor Server application, I am trying to query the database (via EF) on a timer and load data if there is...
Read more >OwningComponentBase<T>
When our OwningComponentBase<T> component is disposed, its IServiceProvider ( Service property) is disposed too, which in turn will dispose of every instance it ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@glararan here is an example on how to do this. https://github.com/javiercn/CancellableWorkBlazor
Works like charm! Thank you for example.