Skip to content

System.InvalidOperationException: Error: No element is currently associated with component 0 #51393

Closed
@XorZy

Description

@XorZy

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have been getting a lot of circuit crashes with "System.InvalidOperationException: Error: No element is currently associated with component X' when navigating away from a specific server interactive page.
I've had a hard time finding the cause of the issue but I've narrowed it down to a component that takes too long to render synchronously.

EDIT: I was not able to reproduce the issue on 7.0.11

Expected Behavior

The circuit should not crash and the app should continue to run as normal.
It's easy to avoid the exception by making all work asynchronous, but it may be difficult to find the source of the issue given the vagueness of the exception.
I should note that I have been able to reproduce the issue with timeouts as low as 12ms.
I think I see why this is happening but imo if the component has already been disposed then the framework should not try to render it and no exception should be raised.

Steps To Reproduce

Here is a minimal example that will raise the exception every single time on my machine:
(Obviously this is a simplified example that serves no purpose but in my case the component was calling a synchronous method that, under specific circumstances, could take a little while to return).

@page "/counter"
@attribute [RenderModeInteractiveServer]
@inject NavigationManager NavigationManager;

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

@{
    if (currentCount > 0)
    {
        Thread.Sleep(500);
    }
    
}

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
        NavigationManager.NavigateTo("/");
    }
}

When you click on the button, you will be redirected to the home page and the circuit will crash.

Exceptions (if any)

fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'w85YXLa05o0keP-wQRM_Bve_qfw2WV04E30hNBMooXs'.
System.AggregateException: One or more errors occurred. (Error: No element is currently associated with component 0)
---> System.InvalidOperationException: Error: No element is currently associated with component 0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
--- End of inner exception stack trace ---

.NET Version

8.0.100-rc.2.23502.2

Anything else?

.NET SDK:
Version: 8.0.100-rc.2.23502.2
Commit: 0abacfc2b6

Runtime Environment:
OS Name: endeavouros
OS Version:
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/8.0.100-rc.2.23502.2/

.NET workloads installed:
There are no installed workloads to display.

Host:
Version: 8.0.0-rc.2.23479.6
Architecture: x64
Commit: 0b25e38ad3

.NET SDKs installed:
8.0.100-rc.1.23463.5 [/usr/share/dotnet/sdk]
8.0.100-rc.2.23502.2 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.0-rc.1.23419.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor Components

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions