HttpClient has no definition for GetJsonAsync

I’m currently tapping into Blazor, and want to move my code so it’s more readable and reusable. In my razor component, the Method works flawlessly – in a Class, it doesn’t.

In my component, I can simply use this:

response = await Http.GetJsonAsync<T>(Uri);

In my Class, Visual Studio complains that System.Net.Http’s HttpClient contains no definition for GetJsonAsync – but I’m getting a typed response, so I want to deserialize it properly.


As of preview 8, you need:

<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />

NOTE: This was correct at the time, but as of Blazor version 3.1.0 this may have changed again so that now you most likely want the System.Net.Http.Json package. See the answer from @JohnB below.

Leave a Reply

Your email address will not be published. Required fields are marked *