With latest release of .NET 6, several components are now throwing JSDisconnectedException when Blazor disposes

To reproduce this issue, create the Blazor Server template project, install Radzen and then add a Blazor page with the below code. Run it in debug, go the test page, then stop debug. All the exceptions will be thrown while the environment disposes. This isn't happening on all components, but certainly the three in this example.

@page "/Test"

<RadzenDropDown TValue=string Data=this.DropDownDataSource @bind-Value=this.DropDownValue />

<RadzenDataGrid TItem=DataGridItem Data=this.DataGridDataSource>
    <Columns>
        <RadzenDataGridColumn TItem=DataGridItem Property=@nameof(DataGridItem.ColumnValue) />
    </Columns>
</RadzenDataGrid>

<RadzenDatePicker @bind-Value=this.DatePickerValue />

@code {
    public Test()
    {
        this.DropDownDataSource = new List<string>{"%", "£/$/€"};
        this.DataGridDataSource = this.DropDownDataSource.Select(d => new DataGridItem(d)).ToList();
    }

    public string? DropDownValue { get; set; }
    public DateTime DatePickerValue { get; set; }
    public IEnumerable<string> DropDownDataSource { get; set; }
    public IEnumerable<DataGridItem> DataGridDataSource { get; set; }

    public class DataGridItem
    {
        public DataGridItem(string value)
        {
            this.ColumnValue = value;
        }

        public string ColumnValue { get; set; }
    }
}

Hi @Daeymon,

I'm afraid that we cannot do much to avoid this. More info here:

So, for DataGrids at least, I'm guessing the culprit is this:

JSRuntime.InvokeVoidAsync("Radzen.destroyPopup", $"{PopupID}{column.GetFilterProperty()}");

If the JSRuntime is disconnected then there is no point running this loop, so why not run a catch on JSDisconnectedException and avoid running code which will just error.

if (IsJSRuntimeAvailable)
{
    foreach (var column in allColumns.ToList().Where(c => c.Visible))
    {
        try
        {
            JSRuntime.InvokeVoidAsync("Radzen.destroyPopup", $"{PopupID}{column.GetFilterProperty()}");
        }
        catch (JSDisconnectedException)
        {
            break;
        }
    }
}

Edit:
Just occurred to me that this will not work, since your running an async method synchronously. My example would only work if ran and awaited within an AsyncDispose method.

Has this issue been resolved in .NET 7 ?
I'm facing the same issue in .NET 6.

The latest version supports .NET 8 and we cannot reproduce such issue.

1 Like