Home
Support Forums

Issues publishing Blazor Webassembly

I’ve created a basic Webassembly app through Visual Studio and have done zero customizations.

I can browse to the server folder and run dotnet watch run and it works fine.

I have committed it to Github. In the root of the repository I added a file named “netlify.toml” and added the following code.

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

I then created a new site in my Netlify account that pulls from that Github repository and made the following deploy setting changes.

  • Build command: dotnet publish -c Release -o release
  • Publish directory: release/wwwroot

I save it and it deploys the app. The app loads and the counter page works, the Fetch data page gives me this error.

“crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: ExpectedStartOfValueNotFound, < Path: $ | LineNumber: 0 | BytePositionInLine: 0.
System.Text.Json.JsonException: ExpectedStartOfValueNotFound, < Path: $ | LineNumber: 0 | BytePositionInLine: 0.
—> System.Text.Json.JsonReaderException: ExpectedStartOfValueNotFound, < LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes) at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first) at System.Text.Json.Utf8JsonReader.ReadSingleSegment() at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.Serialization.JsonConverter1[[Test.Shared.WeatherForecast, Test.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
Exception_EndOfInnerExceptionStack
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
at System.Text.Json.Serialization.JsonConverter1[[Test.Shared.WeatherForecast[], Test.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadCore[WeatherForecast[]](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadCore[WeatherForecast[]](JsonReaderState& readerState, Boolean isFinalBlock, ReadOnlySpan1 buffer, JsonSerializerOptions options, ReadStack& state, JsonConverter converterBase)
at System.Text.Json.JsonSerializer.d__201[[Test.Shared.WeatherForecast[], Test.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at System.Net.Http.Json.HttpContentJsonExtensions.<ReadFromJsonAsyncCore>d__31[[Test.Shared.WeatherForecast, Test.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
at System.Net.Http.Json.HttpClientJsonExtensions.d__9`1[[Test.Shared.WeatherForecast, Test.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
at Test.Client.Pages.FetchData.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)”

Any ideas?

Not particularly familiar with your stack, but…

I believe, this line says that it was unable to parse a JSON. From my understanding, the JSON file doesn’t exist and because of the redirect rule, the /index.html page got served which starts with <. I this is not the case, could you help us with the site name so we could check?

Yes, here it is.

https://quizzical-meninsky-de8b32.netlify.app/

yeah it looks like exactly what I’ve explained above. You’re trying to fetch this: Test but it’s returning your /index.html:

Make sure WeatherForecast is a URL that actually exists and returns a valid JSON.

That does seem to be the case, this project is split in to 3 projects

Client <= web app
Server <= api
Shared <= models shared between the two others

I’m not sure that Netlify is compiling and running both the client and server projects, just the client, so when the WeatherForecast call is made to the API, nothing is there to respond.

I can’t directly browse to the link it’s looking for. How can I ensure that both projects are being built and run?

Thank you!

hi there, would it help to download your website and see what we are actually building vs what you think we are building? :thinking:

I don’t believe Netlify can run a server, so you might have to build and host the server part somewhere else. That is, unless you’re willing to use Netlify Functions to write the server-side functionality in JS or Go.