Skip to content

Critical Bug: Blazor Server – SignalR NullReferenceException when closing modal and updating QuickGridΒ #62858

@yvanddivans

Description

@yvanddivans

πŸ“‹ Description

In a Blazor Server app, when a modal component is closed (via @if) and an EventCallback adds an item to a list bound to a QuickGrid, the server crashes with a NullReferenceException in SignalR.

This causes:

  • The entire app to freeze
  • The SignalR circuit to die silently
  • No exception being caught by any ErrorBoundary

πŸ§ͺ Repro steps

  1. A parent component displays a QuickGrid bound to a list: List<InvoiceDetailsModel>
  2. A modal component is shown via @if (IsModalVisible)
  3. On form submit inside the modal, an EventCallback adds an item to the list and sets IsModalVisible = false
  4. This causes Blazor to:
    • Dispose the modal component
    • Re-render the QuickGrid
  5. At this point, SignalR crashes with a NullReferenceException

πŸ’£ What actually happens

  • RemoteJSRuntime.EndInvokeDotNet(...) throws NullReferenceException
  • The app freezes completely
  • No exception bubbles up
  • Reproducible 100% of the time

βœ… What has been tried (and failed)

Attempted Fix Outcome
Using @key to force modal recreation ❌ No effect
Implementing IDisposable and detaching event handlers βœ… Called, no leak β€” but still crashes
Wrapping EventCallback in InvokeAsync() or Task.Yield() ❌ Still crashes
Resetting bound model before disposal (Detail = new()) ❌ Still crashes
Toggling visibility (Visible=true/false) instead of @if ❌ Same behavior
Delaying updates to parent via Task.Delay() ❌ Still crashes
Removing QuickGrid temporarily βœ… Prevents crash β†’ likely trigger is grid rerender

πŸ“Ž Stack trace

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSRuntime.EndInvokeDotNet(DotNetInvocationInfo invocationInfo, DotNetInvocationResult& invocationResult)
   at Microsoft.AspNetCore.SignalR.ClientProxyExtensions.SendCoreAsync(...) // decompiled source

🧰 Environment

  • .NET 8.0.x
  • Blazor Server
  • Microsoft.AspNetCore.SignalR.Core (latest)
  • Microsoft.AspNetCore.Components.QuickGrid (stable)

πŸ™ Request

  • Can this be addressed in QuickGrid's rendering logic or the framework’s circuit lifecycle?
  • At minimum, can the runtime guard against this crash instead of throwing from SendCoreAsync()?
  • Should there be documentation or pattern warnings around updating QuickGrid during component disposal?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions