When I dispose my JsObjectWrapperBase-derived object in the DisposeAsync of a component, I get an exception that JsRuntime is null. The problem is from there:
public class JsRuntimeObjectRef : IAsyncDisposable
{
internal IJSRuntime JsRuntime { get; set; }
[JsonPropertyName("__jsObjectRefId")]
public int JsObjectRefId { get; set; }
public async ValueTask DisposeAsync()
{
JsRuntimeObjectRef runtimeObjectRef = this;
// HERE: runtimeObjectRef.JsRuntime is null in the next line
await JSRuntimeExtensions.InvokeVoidAsync(runtimeObjectRef.JsRuntime, "browserInterop.removeObjectRef", new object[1]
{
(object) runtimeObjectRef.JsObjectRefId
}).ConfigureAwait(false);
GC.SuppressFinalize((object) runtimeObjectRef);
}
}
Not sure what might be causing this, it's not null in the object itself, so I added this method to my object:
public new async ValueTask DisposeAsync()
{
// NOTE: For some reason JsObjectRef's JsRuntime is null in DisposeAsync, so this is copied from there
await JsRuntime.InvokeVoidAsync("browserInterop.removeObjectRef", new object[1]
{
JsObjectRef.JsObjectRefId
});
GC.SuppressFinalize(JsObjectRef);
GC.SuppressFinalize(this);
}
I'm using Blazor WASM 6.0.6 on .NET 6.
When I dispose my
JsObjectWrapperBase-derived object in theDisposeAsyncof a component, I get an exception thatJsRuntimeis null. The problem is from there:Not sure what might be causing this, it's not null in the object itself, so I added this method to my object:
I'm using Blazor WASM 6.0.6 on .NET 6.