'Exception: '<' is an invalid start of a value Blazor WebAssembly

Have a problem with receiving data from api using service. Can someone help? Is the problem in receiving html data instead json, but don't know why, tried to make desearialization but doesn't work. Controller:

[Route("api/[controller]")]
[ApiController]
public class ItemController : ControllerBase
{
    private readonly AppDbContext _appDbContext;

    public ItemController(AppDbContext appDbContext)
    {
        _appDbContext = appDbContext;
    }

    [HttpGet]
    public async Task<IActionResult> GetItems()
    {
        return Ok(await _appDbContext.Items.ToListAsync());
    }
}

Service:

public class ItemService : IItemService
{
    private readonly HttpClient _httpClient;

    public ItemService(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    public List<Item> Items { get; set; } = new List<Item>();

    public async Task<List<Item>> GetItems()
    {
        Items = await _httpClient.GetFromJsonAsync<List<Item>>("api/item");
        return Items;
    }
}

BaseClass:

public class ItemsBase : ComponentBase
{
    [Inject]
    public IItemService ItemService { get; set; }

    protected override async Task OnInitializedAsync()
    {
        await ItemService.GetItems();
    }
}


Solution 1:[1]

There is an error in your API, instead of returning List its returning error in the form of html, which starts with <

So debug your API endpoint and see where the error is occurring

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Surinder Singh