Apress / beginning-azure-static-web-apps

Source Code for "Beginning Azure Static Web Apps" by Stacy Cashmore
6 stars 5 forks source link

Viewing the Deployed Application (p 93) #5

Closed pmarangoni closed 4 hours ago

pmarangoni commented 5 hours ago

When I click the link to display the weather, I get an error. The bottom of the browser displays: "An unhandled error has occurred. Reload"

Looking at the console tab of the browser's developer tools, I see this:

Fetch finished loading: GET "https://brave-beach-0632ca71e.5.azurestaticapps.net/api/weather-forecast".

followed by this:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: DeserializeUnableToConvertValue, System.DateOnly Path: $[0].date | LineNumber: 0 | BytePositionInLine: 44. System.Text.Json.JsonException: DeserializeUnableToConvertValue, System.DateOnly Path: $[0].date | LineNumber: 0 | BytePositionInLine: 44. ---> System.FormatException: UnsupportedFormat, DateOnly at System.Text.Json.ThrowHelper.ThrowFormatException(DataType ) at System.Text.Json.Serialization.Converters.DateOnlyConverter.ReadCore(Utf8JsonReader& ) at System.Text.Json.Serialization.Converters.DateOnlyConverter.Read(Utf8JsonReader& , Type , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1[[System.DateOnly, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadJsonAndSetMember(Object , ReadStack& , Utf8JsonReader& ) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1[[Client.Pages.Weather.WeatherForecast, Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnTryRead(Utf8JsonReader& , Type , JsonSerializerOptions , ReadStack& , WeatherForecast& ) at System.Text.Json.Serialization.JsonConverter1[[Client.Pages.Weather.WeatherForecast, Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].TryRead(Utf8JsonReader& , Type , JsonSerializerOptions , ReadStack& , WeatherForecast& , Boolean& ) at System.Text.Json.Serialization.JsonCollectionConverter2[[Client.Pages.Weather.WeatherForecast[], Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Client.Pages.Weather.WeatherForecast, Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnTryRead(Utf8JsonReader& , Type , JsonSerializerOptions , ReadStack& , WeatherForecast[]& ) at System.Text.Json.Serialization.JsonConverter1[[Client.Pages.Weather.WeatherForecast[], Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].TryRead(Utf8JsonReader& , Type , JsonSerializerOptions , ReadStack& , WeatherForecast[]& , Boolean& ) at System.Text.Json.Serialization.JsonConverter1[[Client.Pages.Weather.WeatherForecast[], Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& , WeatherForecast[]& , JsonSerializerOptions , ReadStack& ) Exception_EndOfInnerExceptionStack at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& , Utf8JsonReader& , Exception ) at System.Text.Json.Serialization.JsonConverter1[[Client.Pages.Weather.WeatherForecast[], Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& , WeatherForecast[]& , JsonSerializerOptions , ReadStack& ) at System.Text.Json.Serialization.Metadata.JsonTypeInfo1[[Client.Pages.Weather.WeatherForecast[], Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ContinueDeserialize(ReadBufferState& , JsonReaderState& , ReadStack& , WeatherForecast[]& ) at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.d1[[Client.Pages.Weather.WeatherForecast[], Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at System.Net.Http.Json.HttpClientJsonExtensions.<gCore|12_0>d2[[Client.Pages.Weather.WeatherForecast[], Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Text.Json.JsonSerializerOptions, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].MoveNext() at Client.Pages.Weather.OnInitializedAsync() at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )

Any idea what has happened?

pmarangoni commented 4 hours ago

I think I figured out the problem. I built my client project with the most current version of .NET, which in my case is 9. The sample pages for a WebAssembly Blazor project have the WeatherForecast class with a DateOnly property named Date. Apparently, the JSRuntime doesn't support DateOnly. I changed the type to DateTime (which is how you have it in your code) and it all works fine now.