I have a Blazor WASM application that I publish to a server where it's run as an IIS site.
I've just converted it to .NET 8 and in DEBUG and RELEASE modes it executes just fine on my machine in Visual Studio.
However, when I publish it either as a self-contained app or as a portable app then I get the following exception when it runs one page in the site:
aspnetcore-browser-refresh.js:1 Failed to load resource: the server responded with a status of 404 ()2blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: The deserialization constructor for type 'System.Collections.Generic.KeyValuePair`2[System.String,System.String]' contains parameters with null names. This might happen because the parameter names have been trimmed by ILLink. Consider using the source generated serializer instead.System.NotSupportedException: The deserialization constructor for type 'System.Collections.Generic.KeyValuePair`2[System.String,System.String]' contains parameters with null names. This might happen because the parameter names have been trimmed by ILLink. Consider using the source generated serializer instead. at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context)--- End of stack trace from previous location --- at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at SmartTools.Client.Pages.BotAnalyserToolsPages.DatabaseComparerBase.CompareAsync() at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at SmartTools.Client.Pages.BotAnalyserToolsPages.DatabaseComparer.<BuildRenderTree>b__0_27() at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at MudBlazor.MudBaseButton.OnClickHandler(MouseEventArgs ev) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )Ft @ blazor.webassembly.js:1Digging into the method that generates the error, I have the following lines of code:
JsonSerializerOptions options = new() { PropertyNameCaseInsensitive = true };List<KeyValuePair<string, string>> items = JsonSerializer.Deserialize<List<KeyValuePair<string, string>>>(data, options)!;If I include the following line:
Console.WriteLine($"data: '{data}'");And inspect this in the Browser's console, then I see that data is as I would expect, namely:
[ {"key" : "some key","value" : "some value }, {"key" : "some key","value" : "some value }, ... etc]If I capture that exact JSON and execute the following in LinqPad
List<KeyValuePair<string, string>> list = JsonSerializer.Deserialize<List<KeyValuePair<string, string>>>(dataFromConsole, options)!;then it works absolutely perfectly.