question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET 6 Blazor server app not Disposing razor pages on browser tab close

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When IDisposable is implemented in razor page and browser tab is closed by user, the Dispose method is called after few minutes and not immediately after tab close. The very first thing I’d mention is that disposing of razor pages worked correctly in .NET 5 so apparently it’s a bug in .NET 6 (or ASP.NET Core Runtime). Problem started to appear after I’ve upgraded my project to .NET 6.

This problem was discused previously in https://github.com/dotnet/aspnetcore/issues/38147 but solution in answer does not solve this problem - .NET knows about tab being closed but just do not call Dispose.

Expected Behavior

When browser tab is closed .NET should dispose all razor pages that existed in this session.

Steps To Reproduce

  1. Create Blazor server app according to https://dotnet.microsoft.com/en-us/learn/aspnet/blazor-tutorial/create
  2. Implement IDisposable in Counter.razor and set breakpoint in Dispose method
  3. Add HubFilter using builder.Services.Configure<HubOptions>(O => O.AddFilter<HubFilter>()); and set breakpoint in OnDisconnectedAsync
  4. Start app and navigate to /counter
  5. Close tab
  6. OnDisconnectedAsync is called but Dispose is not.

Exceptions (if any)

No response

.NET Version

6.0.101

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffraskacommented, Jan 7, 2022

I studied problem further and it looks like problem appear in Vivaldi and Firefox but not in Google Chrome. So it’s somehow browser issue.

0reactions
msftbot[bot]commented, Jan 11, 2022

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to detect that a client closed the browser on Blazor ...
1 Answer 1 · 1. This only detects when user leaves the page. It cannot differ between a link click (changing page) or...
Read more >
ASP.NET Core Blazor state management
Learn how to persist user data (state) in Blazor apps. ... The user might close and reopen their browser or reload the page,...
Read more >
Dependency Injection Scopes in Blazor
Coming from ASP.NET Core, it seems that the dependency injection scope in Blazor works differently. This article shows why this is the case....
Read more >
Blazor's New LocationChanging Events in .NET 7
It's worth knowing the limitations of the LocationChanging event—the main one being that it doesn't always fire when you might want/need it to....
Read more >
Guide to Blazor JavaScript Interop - Imaginet Blog
Learn how to use Blazor JavaScript Interop to make JavaScript and .NET code interact seamlessly. Get up and running quickly with step-by-step..
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found