Skip to content

Comments

Fix WebAssembly crash with hybrid JSON serialization approach#40

Merged
alexreich merged 5 commits intomainfrom
copilot/fix-demo-page-crash
Nov 19, 2025
Merged

Fix WebAssembly crash with hybrid JSON serialization approach#40
alexreich merged 5 commits intomainfrom
copilot/fix-demo-page-crash

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Fix WebAssembly NullabilityInfoContext_NotSupported Error ✅

Problem Statement

The GitHub Pages demo site crashed when clicking "New Rule" with the error:

System.InvalidOperationException: NullabilityInfoContext_NotSupported

Updates Based on Testing

Issue 1: After initial fix, error occurred for System.Int64 not in TypeInfoResolver

  • Root cause: InputRuleParameterDictionary.Parameters is Dictionary<string, object> where values can be primitive types
  • Fix: Added primitive types to source-generated context

Issue 2: After adding primitives, error occurred for System.Dynamic.ExpandoObject not in TypeInfoResolver

  • Root cause: Dictionary<string, object> values can be any dynamic type created by DynamicJsonConverter (primitives, arrays, ExpandoObject, etc.)
  • Fix: Use separate reflection-based JsonSerializerOptions for serializing dynamic content in UpdateInputs() method

Solution Implemented - Hybrid Approach

  • Updated RulesEngineJsonSourceContext.cs to include:
    • JsonElement type for dynamic JSON deserialization
    • Serialization options: DefaultIgnoreCondition.WhenWritingNull, PropertyNameCaseInsensitive = true
    • Primitive types: string, int, long, double, bool, decimal, object
  • Modified RulesEngineEditorPage.razor.cs:
    • Initialize jsonOptions from source-generated context for general use (AOT-compatible)
    • Use separate reflection-based options in UpdateInputs() for dynamic content serialization
  • Verified all builds succeed (Debug, Release, Publish)
  • Verified NuGet package creation succeeds

Technical Details

The fix uses a hybrid approach to balance AOT compatibility with dynamic content needs:

  • Source-generated serialization (jsonOptions with RulesEngineJsonSourceContext) for most operations - maintains AOT compatibility
  • Reflection-based serialization (separate JsonSerializerOptions in UpdateInputs()) for truly dynamic Dictionary<string, object> content where values can be any type returned by DynamicJsonConverter

This 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 , Nullable1 , 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 , Nullable1 , 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[List1](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

    steps:
        - name: checkout code
          uses: actions/checkout@v2

        - name: setup .net core sdk
          uses: actions/setup-dotnet@v1
          with:
              dotnet-version:  8.*

        - name: dotnet build
          run: dotnet build RulesEngineEditor.sln --configuration Release

        - name: dotn...

💡 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.

…lization

Co-authored-by: alexreich <9328531+alexreich@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unhandled exception on demo page Fix WebAssembly crash caused by reflection-based JSON serialization Nov 19, 2025
Copilot AI requested a review from alexreich November 19, 2025 01:52
@alexreich
Copy link
Owner

@copilot -

site still crashes in same spot

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: JsonTypeInfo metadata for type 'System.Int64' was not provided by TypeInfoResolver of type 'RulesEngineEditor.Shared.RulesEngineJsonSourceContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically. The unsupported member type is located on type 'System.Object'. Path: $.Parameters.
System.NotSupportedException: JsonTypeInfo metadata for type 'System.Int64' was not provided by TypeInfoResolver of type 'RulesEngineEditor.Shared.RulesEngineJsonSourceContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically. The unsupported member type is located on type 'System.Object'. Path: $.Parameters.
 ---> System.NotSupportedException: JsonTypeInfo metadata for type 'System.Int64' was not provided by TypeInfoResolver of type 'RulesEngineEditor.Shared.RulesEngineJsonSourceContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.WriteStackFrame.InitializePolymorphicReEntry(Type runtimeType, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter.ResolvePolymorphicConverter(Object value, JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Object& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.DictionaryOfTKeyTValueConverter`3[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnWriteResume(Utf8JsonWriter writer, Dictionary`2 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonDictionaryConverter`3[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter writer, Dictionary`2 dictionary, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Dictionary`2& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, InputRuleParameterDictionary value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.JsonMetadataServicesConverter`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, InputRuleParameterDictionary value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].TryWrite(Utf8JsonWriter writer, InputRuleParameterDictionary& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.ListOfTConverter`2[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].OnWriteResume(Utf8JsonWriter writer, List`1 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonCollectionConverter`2[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, List`1 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.JsonMetadataServicesConverter`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter writer, List`1 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, List`1& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, List`1& value, JsonSerializerOptions options, WriteStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, Exception innerException)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, List`1& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Serialize(Utf8JsonWriter writer, List`1& rootValue, Object rootValueBoxed)
   at System.Text.Json.JsonSerializer.WriteString[List`1](List`1& value, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[List`1](List`1 value, JsonSerializerOptions options)
   at RulesEngineEditor.Pages.RulesEngineEditorPage.UpdateInputs() in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Pages\RulesEngineEditorPage.razor.cs:line 233
   at RulesEngineEditor.Pages.RulesEngineEditorPage.WorkflowUpdate() in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Pages\RulesEngineEditorPage.razor.cs:line 189
   at RulesEngineEditor.Services.WorkflowService.WorkflowUpdate() in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Services\WorkflowService.cs:line 28
   at RulesEngineEditor.Services.WorkflowService.NewRule(Object ruleParent) in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Services\WorkflowService.cs:line 44
   at RulesEngineEditor.Pages.RulesEngineEditorPage.<>c__DisplayClass90_1.<BuildRenderTree>b__20() in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Pages\RulesEngineEditorPage.razor:line 108
   at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[Object](MulticastDelegate delegate, Object arg)
   at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync(Object arg)
   at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, Object arg)
   at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync(Object arg)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync(UInt64 eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs, Boolean waitForQuiescence)

…alues

Co-authored-by: alexreich <9328531+alexreich@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

@copilot -

site still crashes in same spot
...

Fixed in commit ee12344. The issue was that InputRuleParameterDictionary.Parameters is a Dictionary<string, object>, and when serializing, the dictionary values can be primitive types (Int64, string, bool, double, etc.). I've added all common primitive types to the source-generated JSON context so they can be properly serialized in WebAssembly with AOT.

The context now includes: string, int, long, double, bool, decimal, and object types.

@alexreich
Copy link
Owner

@copilot

Crashes same place on expando object

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: JsonTypeInfo metadata for type 'System.Dynamic.ExpandoObject' was not provided by TypeInfoResolver of type 'RulesEngineEditor.Shared.RulesEngineJsonSourceContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically. The unsupported member type is located on type 'System.Object'. Path: $.Parameters.
System.NotSupportedException: JsonTypeInfo metadata for type 'System.Dynamic.ExpandoObject' was not provided by TypeInfoResolver of type 'RulesEngineEditor.Shared.RulesEngineJsonSourceContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically. The unsupported member type is located on type 'System.Object'. Path: $.Parameters.
 ---> System.NotSupportedException: JsonTypeInfo metadata for type 'System.Dynamic.ExpandoObject' was not provided by TypeInfoResolver of type 'RulesEngineEditor.Shared.RulesEngineJsonSourceContext'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.WriteStackFrame.InitializePolymorphicReEntry(Type runtimeType, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter.ResolvePolymorphicConverter(Object value, JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Object& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.DictionaryOfTKeyTValueConverter`3[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnWriteResume(Utf8JsonWriter writer, Dictionary`2 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonDictionaryConverter`3[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter writer, Dictionary`2 dictionary, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Dictionary`2& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, InputRuleParameterDictionary value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.JsonMetadataServicesConverter`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, InputRuleParameterDictionary value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].TryWrite(Utf8JsonWriter writer, InputRuleParameterDictionary& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.ListOfTConverter`2[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].OnWriteResume(Utf8JsonWriter writer, List`1 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonCollectionConverter`2[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, List`1 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.JsonMetadataServicesConverter`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter writer, List`1 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, List`1& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, List`1& value, JsonSerializerOptions options, WriteStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, Exception innerException)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, List`1& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Collections.Generic.List`1[[RulesEngineEditor.Models.InputRuleParameterDictionary, RulesEngineEditor, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Serialize(Utf8JsonWriter writer, List`1& rootValue, Object rootValueBoxed)
   at System.Text.Json.JsonSerializer.WriteString[List`1](List`1& value, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[List`1](List`1 value, JsonSerializerOptions options)
   at RulesEngineEditor.Pages.RulesEngineEditorPage.UpdateInputs() in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Pages\RulesEngineEditorPage.razor.cs:line 233
   at RulesEngineEditor.Pages.RulesEngineEditorPage.WorkflowUpdate() in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Pages\RulesEngineEditorPage.razor.cs:line 189
   at RulesEngineEditor.Services.WorkflowService.WorkflowUpdate() in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Services\WorkflowService.cs:line 28
   at RulesEngineEditor.Services.WorkflowService.NewRule(Object ruleParent) in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Services\WorkflowService.cs:line 44
   at RulesEngineEditor.Pages.RulesEngineEditorPage.<>c__DisplayClass90_1.<BuildRenderTree>b__20() in C:\Users\alex\source\repos\alexreich\RulesEngineEditor\src\RulesEngineEditor\Pages\RulesEngineEditorPage.razor:line 108
   at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[Object](MulticastDelegate delegate, Object arg)
   at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync(Object arg)
   at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, Object arg)
   at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync(Object arg)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync(UInt64 eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs, Boolean waitForQuiescence)

…ionary content

Co-authored-by: alexreich <9328531+alexreich@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

@copilot

Crashes same place on expando object
...

Fixed in commit fc930f9. The issue was that Dictionary<string, object> in InputRuleParameterDictionary.Parameters can contain any dynamic type created by the DynamicJsonConverter - primitives, arrays, ExpandoObject, etc.

Source-generated JSON serialization doesn't support truly dynamic content, so I've updated UpdateInputs() to use a separate reflection-based JsonSerializerOptions for serializing the input parameters. The rest of the application still uses the source-generated context for AOT compatibility.

Copilot AI changed the title Fix WebAssembly crash caused by reflection-based JSON serialization Fix WebAssembly crash with hybrid JSON serialization approach Nov 19, 2025
@alexreich alexreich marked this pull request as ready for review November 19, 2025 02:21
@alexreich alexreich merged commit 22fb1b7 into main Nov 19, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GHP Broken + Nuget will no longer build

2 participants