I am working of another older project of mine as reference and within this blazor compononent I get this error ->

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
   at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[List`1](String value, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[List`1](String value)
   at FinnivoLicenseManagement.Client.Pages.LandingPage.LoadData()
   at FinnivoLicenseManagement.Client.Pages.LandingPage.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

This happens as soon as the page loads up. The API is not even called when this happens. After the error appears the API call starts. Tested the api within the page and it is working fine.

Here is my component code->

@page "/landing"
@using FinnivoLicenseManagement.Shared
@using Newtonsoft.Json;
@layout NoMenuLayout
@inject NavigationManager UriHelper
@inject HttpClient _httpClient

@if (IsLoading)
{
<div class="spinner-border" role="status" justify-content:center; position:center;">
    @*<span class="sr-only"/>*@
</div>
}
else{
<div class="container">
    <h1 class="text-center">Module Usage</h1>
    <table class="table">
        <thead>
            <tr>
                <th>Module</th>
                <th>Number of Users</th>
                <th>Manage</th>
            </tr>
        </thead>
        <tbody>

            @foreach (var module in moduleDetailsList)
            {
                <tr>
                    <td>@module.ModuleName</td>
                    <td>
                        @module.NumberOfUsers
                    </td>
                    <td>
                        <div>
                            <button class="btn btn-primary" @onclick="@(() => NavigateToEdit(module.Id))">Manage Module Licenses</button>
                        </div>
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>
}



@code {
    private bool IsLoading { get; set; }
    List<ModuleDetails> moduleDetailsList = new List<ModuleDetails>();

    protected override async Task OnInitializedAsync()
    {
        IsLoading = true;
        await LoadData();
        IsLoading = false;
    }

    protected async Task LoadData()
    {
        var response = await _httpClient.GetAsync("api/ModuleDetails/GetModuleDetails");
        if (response.IsSuccessStatusCode)
        {
            var jsonResult = await response.Content.ReadAsStringAsync();
            moduleDetailsList = JsonConvert.DeserializeObject<List<ModuleDetails>>(jsonResult);

        }
        moduleDetailsList?.ToList();
    }

    private void NavigateToEdit(int moduleId)
    {
        UriHelper.NavigateTo($"/managemodule/{moduleId}");
    }
}

Is there anything i am missing or doing wrong? My reference project works 100%.

Tried a different way of parsing the data. Needs to populate the list moduleDetailsList.

Any advice on what to try will be appreciated

0

There are 0 best solutions below