System.Text.Json.JsonException: The input does not contain any JSON tokens

Broad3857 picture Broad3857 · Mar 10, 2020 · Viewed 12.8k times · Source

I'm just trying to use a Http POST method in a Blazor app through

public async Task CreateUnit(UnitEntity unit)
{
    await _http.PostJsonAsync<UnitEntity>("api/units", unit);
}

_http and myObject have been defined elsewhere, but I'm getting this weird error. Can anyone help? This is the closest thing I could find elsewhere: https://github.com/dotnet/runtime/issues/30945.

The full error message is

System.Text.Json.JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.

And it here's the stack

enter image description here

Answer

Lukas picture Lukas · Dec 21, 2020

Another reason this error could pop up, as it did for me, is simply because the API endpoint doesn't exist because it was misspelled.