Conversation
|
@vnbaaij for me it is still not working. I still get a disposed error: This can be reproduced with the steps from this: #4248 (comment) |
|
I'm gonna check it out this evening, might join this pr for some pair programming :) |
|
@vnbaaij I set up a try catch here to debug this and the root of this issue is that the dotNetReference has been disposed but is not null. |
|
✅ All tests passed successfully Details on your Workflow / Core Tests page. |
|
@vnbaaij I found a working solution. In line 28 add: private bool _disposed;In line 244 change to: if (_jsModule is not null && _anchoredRegionModule is not null && _dotNetHelper is not null && !_disposed)as well in line 251 to: if (_jsModule is not null && _anchoredRegionModule is not null && _dotNetHelper is not null && !_disposed && _reinitializeEventListeners)And then update the dispose method to: public async ValueTask DisposeAsync()
{
if (_disposed)
{
return;
}
_disposed = true;
_dotNetHelper?.Dispose();
try
{
if (_jsModule is not null)
{
await _jsModule.InvokeVoidAsync("dispose", Anchor);
await _jsModule.DisposeAsync();
_jsModule = null;
}
if (_anchoredRegionModule is not null)
{
await _anchoredRegionModule.DisposeAsync();
_anchoredRegionModule = null;
}
}
catch (Exception ex) when (ex is JSDisconnectedException ||
ex is OperationCanceledException)
{
// The JSRuntime side may routinely be gone already if the reason we're disposing is that
// the client disconnected. This is not an error.
}
finally
{
GC.SuppressFinalize(this);
}
} |
Summary - Unit Tests Code CoverageSummary
CoverageMicrosoft.FluentUI.AspNetCore.Components - 61.2%
|
|
At least my provided test code doesn't seem to crash when we are doing it this way. |
|
Yeah, I think this solution is in line with what @Tyme-Bleyaert meant. |
|
@vnbaaij we should probably move the disposed check within We should probably do if( _disposed)
{
return;
}right in the beginning and remove it from the 2 if statements |
|
nevermind. I just tried it when it's on top. This gets the error right back to me. |
|
I change the |
- Undo nullable for js object references
|
Sorry wrong button. Should we also move _dotNetHelper = DotNetObjectReference.Create(this);into the constructor? |
No, we always do that in |
|
@vnbaaij you are right. I was thinking wrong here. It wouldn't make a difference anyways since the method is only run on firstRender. |
|
@vnbaaij I tried my demo now in WebAssembly and it seems like the disposing here is a bit faster which triggers the exception earlier. |

More fixes for #4248:
IJSObjectReferences nullableDisposeAsyncDotNetObjectReferenceinOnAfterRenderAsyncI'll wait with merging this time till we are all on the same page :)