Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a Blazor Webassembly project with a controller method as follows:

[HttpGet]
    public async Task<List<string>> GetStatesForProfile()
    {
        IConfigurationSection statesSection = configuration.GetSection("SiteSettings:States");
        var sections = statesSection.GetChildren();
        var states = statesSection.GetChildren().Select(s => s.Key).ToList<string>();
        return states;            
    }

The razor page calls this method:

private async Task<bool> GetStatesModel()
{
    try
    {
        States = await http.GetJsonAsync<List<string>>("api/account/getstatesforprofile");            
        ...
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Exception: {ex.Message}, Inner: {ex.InnerException.Message}");
    }

I get this Exception:

Exception: '<' is an invalid start of a value.

I read these values from appsettings.json file, And there is no '<' in values.

{      
  "SiteSettings": {    
    "States": {
      "New York": ["NYC"],
      "California": ["Los Angeles", "San Francisco"]
    }
 }

Also I put a breakpoint in the controller method and it doesn't hit. What is this error? Is it from parsing json? and how to resolve this?

like image 759
mz1378 Avatar asked Apr 28 '20 18:04

mz1378


Video Answer


3 Answers

It happens when you're trying to access an API that doesn't exist. You have to check your API project connectionstring under AppSettings and make sure it's correct and running. If it's a Blazor project, you can set it as your default project, execute and see if you get a json response.

like image 177
Nelson Polomolok Avatar answered Oct 20 '22 00:10

Nelson Polomolok


This error indicates a mismatch of the project targeting framework version and installed runtime on the machine. So make sure that the target framework for your project matches an installed runtime - this could be verified by multiple means; one of them is to check out the Individual Components tab of the Visual Studio Installer and lookup the target version.

E.g., there is the TargetFramework attribute in the proj file:

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

The launch the Visual Studio Installer, click Modify, and visit the Individual Components tab:

Needed framework not installed

Install the missing runtime (.NET 5 Runtime in this case) and you're good to go.

like image 24
Bozhidar Stoyneff Avatar answered Oct 20 '22 00:10

Bozhidar Stoyneff


I had a very similar problem.

In the end it turned out that my browser had cached the HTML error page (I guess I had some problems with the code when I first tried it). And no matter how I tried fixing the code I still only got the error from cache. Clearing my cache also cleared the problem.

like image 33
Lauri Peltonen Avatar answered Oct 19 '22 23:10

Lauri Peltonen