© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
25 replies
Jonathan

Error Accessing a User in Blazor

I am trying to setup my first Blazor project after being away from dotnet for a while to chase the javsacript world and I am completely stuck on something simple.

I have created a new blazor app with the template and enabled Individual Accounts for auth. I am simply trying to get the current user information for the home screen and I get an error :

 Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'G1M-mKG0EKFb3eev_tf-_Mksjrr5QqWRiMMBvnuRCh4'.
      System.ObjectDisposedException: Cannot access a disposed object.
 Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'G1M-mKG0EKFb3eev_tf-_Mksjrr5QqWRiMMBvnuRCh4'.
      System.ObjectDisposedException: Cannot access a disposed object.


The browser console has the error:
[Error] WebSocket connection to 'ws://localhost:5240/_blazor?id=RIqaRL19VNie_L68N5CkRg' failed: The operation couldn’t be completed. Socket is not connected
[Error] WebSocket connection to 'ws://localhost:5240/_blazor?id=RIqaRL19VNie_L68N5CkRg' failed: The operation couldn’t be completed. Socket is not connected


I have tried to do everything I can find about this. I have tried changing render modes, etc. I am at a complete loss.

The home page is simply this (which I based on the sample account pages)

@page "/"
@using ExampleIssues.Components.Account
@using ExampleIssues.Data
@inject IdentityUserAccessor UserAccessor

<PageTitle>Home</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

@if (user != null)
{
    <div>User here: @user.UserName</div>
}
else
{
    <div>User Not found</div>
}

@code {
    
    private ApplicationUser user = default!;
    
    [CascadingParameter] private HttpContext HttpContext { get; set; } = default!;
    protected override async Task OnInitializedAsync()
    {
        user = await UserAccessor.GetRequiredUserAsync(HttpContext);
    }
}
@page "/"
@using ExampleIssues.Components.Account
@using ExampleIssues.Data
@inject IdentityUserAccessor UserAccessor

<PageTitle>Home</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

@if (user != null)
{
    <div>User here: @user.UserName</div>
}
else
{
    <div>User Not found</div>
}

@code {
    
    private ApplicationUser user = default!;
    
    [CascadingParameter] private HttpContext HttpContext { get; set; } = default!;
    protected override async Task OnInitializedAsync()
    {
        user = await UserAccessor.GetRequiredUserAsync(HttpContext);
    }
}



I have put the entire repo here:

https://github.com/jmarbutt/ExampleIssues/tree/main/ExampleIssues
GitHub
ExampleIssues/ExampleIssues at main · jmarbutt/ExampleIssues
Contribute to jmarbutt/ExampleIssues development by creating an account on GitHub.
ExampleIssues/ExampleIssues at main · jmarbutt/ExampleIssues
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

User Secrets in Blazor Web Assembly
C#CC# / help
17mo ago
Getting user credentials blazor
C#CC# / help
2y ago
Blazor webassembly Checking if user is logged in
C#CC# / help
3y ago
(Blazor) I'm having trouble accessing a variable inside a parent component.
C#CC# / help
2y ago