Datagrid - Renders Empty on F5 of browser

I have a datagrid that I am populating similar to the documentation but have noticed that if I do a F5 in the browser to refresh the page, the datagrid becomes blank. When I look at the debugger, I get the following exception:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SocketsHttpHandler'....

Here is my code to load the page:

public IEnumerable<AuditConfiguration> configs;
private CancellationToken cancellationToken;

protected override async Task OnInitializedAsync()
{
    configs = await apiClient.GetAllConfigurations(cancellationToken);
}
<RadzenDataGrid @ref="configGrid" AllowFiltering="true" AllowColumnResize="true" AllowSorting="true"
            Data="@configs" TItem="AuditConfiguration" EditMode="DataGridEditMode.Single">

Is there something else I am missing to keep the data (re)loaded in the grid? I'm assuming this is typical Blazor (server side) behavior but I can't find anything about using a different event to load the data on page/component load.

Thanks,
Greg :thinking:

Hi @gknierim,

You are populating the DataGrid properly however in my opinion this code might be crashing on reload for some reason:

Try to debug it to check what's going on.

I debugged it and the api call does get called on the refresh but it is not returning any records which is strange because it works the first time. I'll have to look into it some more.

I figured out the issue. It was when I was creating my HttpClientHandler in Program.cs. I had to pass false to the constructor to not dispose of the handler.

builder.Services.AddScoped<HttpClient>(s =>
{
    var client = new HttpClient(handler, false) { BaseAddress = auditAPIUrl };
    return client;
});

Brother, I'm Having this Same Issue, But I can't find out HttpClient Handler...

Please Help me out.

I found this Code

services.AddScoped(serviceProvider =>
{

          var uriHelper = serviceProvider.GetRequiredService<NavigationManager>();

          return new HttpClient()
          {
            BaseAddress = new Uri(uriHelper.BaseUri)
          };
        });