Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsRuntime is null on dispose on JsObjectWrapperBase #258

Open
cpiber opened this issue Apr 27, 2024 · 0 comments
Open

JsRuntime is null on dispose on JsObjectWrapperBase #258

cpiber opened this issue Apr 27, 2024 · 0 comments

Comments

@cpiber
Copy link

cpiber commented Apr 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant