Fix WebAssembly crash with hybrid JSON serialization approach#40
Fix WebAssembly crash with hybrid JSON serialization approach#40
Conversation
…lization Co-authored-by: alexreich <9328531+alexreich@users.noreply.github.com>
|
@copilot - site still crashes in same spot |
…alues Co-authored-by: alexreich <9328531+alexreich@users.noreply.github.com>
Fixed in commit ee12344. The issue was that The context now includes: |
|
Crashes same place on expando object |
…ionary content Co-authored-by: alexreich <9328531+alexreich@users.noreply.github.com>
Fixed in commit fc930f9. The issue was that Source-generated JSON serialization doesn't support truly dynamic content, so I've updated |
Fix WebAssembly NullabilityInfoContext_NotSupported Error ✅
Problem Statement
The GitHub Pages demo site crashed when clicking "New Rule" with the error:
Updates Based on Testing
Issue 1: After initial fix, error occurred for
System.Int64not in TypeInfoResolverInputRuleParameterDictionary.ParametersisDictionary<string, object>where values can be primitive typesIssue 2: After adding primitives, error occurred for
System.Dynamic.ExpandoObjectnot in TypeInfoResolverDictionary<string, object>values can be any dynamic type created byDynamicJsonConverter(primitives, arrays, ExpandoObject, etc.)JsonSerializerOptionsfor serializing dynamic content inUpdateInputs()methodSolution Implemented - Hybrid Approach
RulesEngineJsonSourceContext.csto include:JsonElementtype for dynamic JSON deserializationDefaultIgnoreCondition.WhenWritingNull,PropertyNameCaseInsensitive = truestring,int,long,double,bool,decimal,objectRulesEngineEditorPage.razor.cs:jsonOptionsfrom source-generated context for general use (AOT-compatible)UpdateInputs()for dynamic content serializationTechnical Details
The fix uses a hybrid approach to balance AOT compatibility with dynamic content needs:
jsonOptionswithRulesEngineJsonSourceContext) for most operations - maintains AOT compatibilityJsonSerializerOptionsinUpdateInputs()) for truly dynamicDictionary<string, object>content where values can be any type returned byDynamicJsonConverterThis approach avoids the impossible task of registering all possible dynamic types in the source-generated context while maintaining AOT compatibility for the rest of the application.
Testing
✅ Debug build successful
✅ Release build successful
✅ WebAssembly publish with AOT successful
✅ NuGet package creation successful
✅ Solution build successful
Original prompt
This section details on the original issue you should resolve
<issue_title>GHP Broken + Nuget will no longer build</issue_title>
<issue_description>1. On demo page - clicking new rule crashes site, "An unhandled error has occurred. Reload"
blazor.webassembly.js:1
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: NullabilityInfoContext_NotSupported
System.InvalidOperationException: NullabilityInfoContext_NotSupported
at System.Reflection.NullabilityInfoContext.EnsureIsSupported()
at System.Reflection.NullabilityInfoContext.Create(PropertyInfo )
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.DeterminePropertyNullability(JsonPropertyInfo , MemberInfo , NullabilityInfoContext )
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulatePropertyInfo(JsonPropertyInfo , MemberInfo , JsonConverter , Nullable
1 , NullabilityInfoContext , Boolean , Boolean ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreatePropertyInfo(JsonTypeInfo , Type , MemberInfo , NullabilityInfoContext , JsonSerializerOptions , Boolean , Boolean ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.AddMember(JsonTypeInfo , Type , MemberInfo , NullabilityInfoContext , Boolean , Boolean , PropertyHierarchyResolutionState& ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.AddMembersDeclaredBySuperType(JsonTypeInfo , Type , NullabilityInfoContext , Boolean , PropertyHierarchyResolutionState& ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateProperties(JsonTypeInfo , NullabilityInfoContext ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type , JsonConverter , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateJsonTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type ) at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context) --- End of stack trace from previous location --- at System.Text.Json.JsonSerializerOptions.CachingContext.CacheEntry.GetResult() at System.Text.Json.JsonSerializerOptions.CachingContext.GetOrAddTypeInfo(Type , Boolean ) at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Nullable1 , Boolean , Boolean )at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.g__ConfigureSynchronized|172_0()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Nullable
1 , Boolean , Boolean ) at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type , Boolean ) at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions , Type ) at System.Text.Json.JsonSerializer.GetTypeInfo[List1](JsonSerializerOptions )at System.Text.Json.JsonSerializer.Serialize[List
1](List1 , JsonSerializerOptions )at RulesEngineEditor.Pages.RulesEngineEditorPage.UpdateInputs()
at RulesEngineEditor.Pages.RulesEngineEditorPage.WorkflowUpdate()
at RulesEngineEditor.Services.WorkflowService.WorkflowUpdate()
at RulesEngineEditor.Services.WorkflowService.NewRule(Object ruleParent)
at RulesEngineEditor.Pages.RulesEngineEditorPage.<>c__DisplayClass90_1.b__20()
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[Object](MulticastDelegate , Object )
at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync(Object )
at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, Object arg)
at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync(Object )
at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync(UInt64 , EventFieldInfo , EventArgs , Boolean )
demo:1
Failed to load resource: the server responded with a status of 404 ()
2. Nuget no longer builds (previous version below)
name: Nuget CI
on:
push:
branches: [ main, release/* ]
pull_request:
branches: [ main, release/* ]
jobs:
build:
runs-on: windows-latest
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.