Error In Blazor Web App

Prathamesh Shende 441 Reputation points
2025-05-06T12:11:45.9733333+00:00

I am getting error in browser console
Project version is .NET 9
Template Blazor Web App Auto Interactive Render

@rendermode @(new InteractiveWebAssemblyRenderMode(false)) after setting data not get loaded and error still there. why data is not get loaded pre render false state?

blazor.web.js:1 
 ManagedError: One or more errors occurred. (Object reference not set to an instance of an object.)
    at sn (marshal-to-js.ts:420:18)
    at Kt.resolve_or_reject (marshal-to-js.ts:315:28)
    at marshal-to-js.ts:363:16
    at marshal-to-js.ts:341:48
    at fr (invoke-js.ts:523:9)
    at Fc (marshal-to-js.ts:341:5)
    at dotnet.native.3c4wvb350q.wasm:0x1f1a4
    at dotnet.native.3c4wvb350q.wasm:0x1c8ae
    at dotnet.native.3c4wvb350q.wasm:0xea19
    at dotnet.native.3c4wvb350q.wasm:0x1ec88
callEntryPoint	@	blazor.web.js:1
await in callEntryPoint		
Hr	@	blazor.web.js:1
await in Hr		
Fr	@	blazor.web.js:1
startWebAssemblyIfNotStarted	@	blazor.web.js:1
resolveRendererIdForDescriptor	@	blazor.web.js:1
determinePendingOperation	@	blazor.web.js:1
refreshRootComponents	@	blazor.web.js:1
(anonymous)	@	blazor.web.js:1
setTimeout		
rootComponentsMayRequireRefresh	@	blazor.web.js:1
onDocumentUpdated	@	blazor.web.js:1
Hi	@	blazor.web.js:1

here is my code

@page "/list"

@inject IDiseaseService _diseasesService
@* @rendermode @(new InteractiveWebAssemblyRenderMode(false)) *@
@rendermode @(new InteractiveWebAssemblyRenderMode(true))

<h3>List</h3>

@if (diseases is not null)
{
    @foreach (var item in diseases.Items)
    {
        @item.Name
        <br />
    }
}

@code {
    PagedResult<Disease> diseases = new();

    protected override async Task OnInitializedAsync()
    {
        var result = await _diseasesService.Get(1, 10, string.Empty, 0);
        if (result?.Value != null)
        {
            diseases = result.Value;
        }              
	} 
}

Blazor Training
Blazor Training
Blazor: A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.Training: Instruction to develop new skills.
32 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 75,156 Reputation points
    2025-05-06T16:43:04.4966667+00:00

    I would guess either _diseasesService is null or its .Get() method is throwing the error.

    Note: HttpClient in Blazor WASM, is not full features and calls javascript to access the network, so it's limited by javascript security (ex. Cross site scripting).


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.