HttpClient fails on Mac M1

Viewed 29

I have a blazor wasm app that I developed on a Windows PC in Visual Studio 2022. I've recently been trying out a MacBook Air M1, with Visual Studio 2022 for Mac Installed.

I copied the VS solution across. It compiles and runs ok until it gets to the following line in the code-behind of a page component:

return await _httpClient.GetFromJsonAsync<IEnumerable<ClientOrg>>($"api/clients");

This should make a http request to a web api project of the same solution but instead, the following error is raised:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: '<' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0. System.Text.Json.JsonException: '<' is an invalid start of a value

The same code works when run on Windows.

Anyone see where I'm going wrong?

1 Answers

The was a dumb mistake but I give myself some slack since this is the first time I've used a mac - Visual Studio for Mac is quite different!

The problem was that the blazor client project was set as the startup project. Once I'd switched to set the blazor server project as start then all worked just the same as when debugging the solution on Windows. I'm sure there'll be more hurdles to jump but so far I'm impressed with being able to build dotnet apps on a Mac with no Intel chip.

Related