5
votes

using Blazor dotnet core 3.1 and getting this error:

The list of component records is not valid

Found a bug report regarding this that was closed in december 2019: https://github.com/dotnet/aspnetcore/issues/14966 enter image description here Don't see any reason for this error and hope there is a workaround (can not make this error each page call, it's just happening very rarely...).

Does anybody has an idea / hint which could cause this?

Thx!

3
I had the same problem and in my cas it wase component parameter that was not json serializable. It looks like error reporting in blazor is lacking - you should try to strip your component of functionality until you get rid of this error. - ghord
Acutally, now that I think about it I had exceptions disabled in VS and it was probably swallowing initialization exception. - ghord

3 Answers

5
votes

I hit the same issue when I upgraded my app from .NET Core 3.0 to .NET Core 3.1 while using Blazor Client. The first "fix" I found was to do a force-refresh on the client (the web browser). That is, I pressed Ctrl+F5 to refresh.

I'm assuming that there was some API call that was being cached on the client and due to some version/format changes from 3.0 to 3.1, the old cached data was no longer valid, causing an error.

I'll be contacting the people who work on Blazor to try to get more info (I work with them at Microsoft).


Update June 1, 2020

I hit this again running my app on Azure App Services. This time even Ctrl+F5 didn't work. But I found https://stackoverflow.com/a/59356356/31668, and applied the fix there, which seemed to fix my problem.

I made a slight change to the code because in my case I use the Azure SignalR service only in staging/production and not in development. So I have this code in my app's Startup.cs ConfigureServices method:

if (!HostingEnvironment.IsDevelopment())
{
    services.AddSignalR().AddAzureSignalR(options =>
    {
        options.ServerStickyMode = Microsoft.Azure.SignalR.ServerStickyMode.Required;
    });
}
3
votes

This issue may happen by browser's automatic Cache control.

Let's say you have two MVC views with Blazor components within: Pages A.cshtml and B.cshtml.

When requesting page A, you receive a html response with the Blazor component rendered and a connection is stablished. Then, you navigate to page B. If you go back to page A (e.g. pressing back button) your browser will use a cached response made previously to fetch page A.

This should break the connection between Client and Server as the component descriptors may be changed. (sometimes seems randonmly).

To solve this, disable this cache behaviour on your _Host.cshtml adding:

@{ 
    Context.Response.Headers["Cache-Control"] = "no-store";
}

This will prevent the caching from your browser and make it request a new page with a correct components descriptor.

References: https://www.gitmemory.com/issue/dotnet/aspnetcore/26174/705472525 https://github.com/dotnet/aspnetcore/issues/18143#issuecomment-585961784

1
votes

In my case it was a class that I was using as a cascade value, but it didn't have a constructor without parameters

public class User 
{
            
    public User(ClaimsPrincipal principal) 
    {
       ....
    }
       ....
 }

 public class User 
 {
    //this fix
    public User(){}
    public User(ClaimsPrincipal principal) 
    {
       ....
    }
       ....
 }

[CascadingParameter]
private User User { get; set; }