-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
In a Blazor Web App, I am using Razor components that inherit OwningComponentBase. Inside of these components, I am overriding the Dispose(bool disposing)-method as such (example):
@inherits OwningComponentBase
<h3>Test</h3>
@code {
protected override void Dispose(bool disposing)
{
if (disposing)
{
Console.WriteLine("disposing test component");
}
base.Dispose(disposing);
}
}
Previously, in .NET 9, upon closing the component (for example by having a boolean to show/hide), the Dispose method is invoked, and disposing == true, which ultimately triggers the Console.WriteLine("disposing test component");. This is the expected behavior.
However, after upgrading to .NET 10, the value of disposing is no longer true but false. Resulting in breaking changes in code (anything in the disposing conditional check is no longer executed).
I was unable to find any reference to this in the breaking changes of NET 10, neither in the change log. All I could find was the following in the "What's new"-section, which does not mention anything about this change:
OwningComponentBase now implements IAsyncDisposable
OwningComponentBase now includes support for asynchronous disposal, improving resource management. There are new DisposeAsync and DisposeAsyncCore methods with an updated Dispose method to handle both synchronous and asynchronous disposal of the service scope.
I consider this to be a major breaking change that is not documented at all. Was this the intended behavior or is this a bug? If it was intended, this has not been documented and this can cause serious memory leaks.
PS: I also tried this with 2 out-of-the-box Blazor projects, one in .NET 9 and the other in .NET 10. Please, find them attached.
Expected Behavior
The OwningComponentBase's Dispose-method should have the value of disposing being set to true in .NET 10 such as it was in .NET 9.
Steps To Reproduce
- Run both projects (one is .NET 9, the other .NET 10).
- Click the button to show the test component.
- Click the button to hide the test component.
- The console will show the statement in the
disposing == trueclause only in the .NET 9 version.
Exceptions (if any)
No response
.NET Version
10
Anything else?
No response