Skip to content

HttpClient inject isn't working in Blazor 0.8 #15328

@tmpacifitech

Description

@tmpacifitech

Hi

I have created a new blazor component and tried to call get data from json file.

@function {
        protected override async Task OnInitAsync()
        {
           data = await Http.GetJsonAsync<GridItem[]>("sample-data/data.json");
        }
}

And got this error:

Uncaught (in promise) Error: System.InvalidOperationException: Cannot provide a value for property 'Http' on type 'BlazorGrid.App.Components.GridComponent'. There is no registered service of type 'System.Net.Http.HttpClient'.
   at Microsoft.JSInterop.DotNetDispatcher.InvokeSynchronously(String assemblyName, String methodIdentifier, Object targetInstance, String argsJson)
   at Microsoft.JSInterop.DotNetDispatcher.BeginInvoke(String callId, String assemblyName, String methodIdentifier, Int64 dotNetObjectId, String argsJson)
    at endInvokeDotNetFromJS (components.server.js:23)
    at components.server.js:23
    at new Promise (<anonymous>)
    at e.beginInvokeJSFromDotNet (components.server.js:23)
    at components.server.js:16
    at Array.forEach (<anonymous>)
    at e.invokeClientMethod (components.server.js:16)
    at e.processIncomingData (components.server.js:16)
    at e.connection.onreceive (components.server.js:16)
    at WebSocket.i.onmessage (components.server.js:16)

What's wrong here?

This is working in Blazor 0.7, but not working in Blazor 0.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions