Dynamic Type Generation fails for heterogeneous lists in Utils.GetTypedObject #715
butterflybee783-sudo
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The current implementation of Utils.CreateAbstractClassType - https://github.com/microsoft/RulesEngine/blob/main/src/RulesEngine/HelperFunctions/Utils.cs#L15
uses a "First-Item-Only" strategy when determining the schema for collections.
var internalType = CreateAbstractClassType(list[0]);The Problem: If the first element in a list is null or has fewer properties than subsequent elements, the generated DynamicClass is incomplete. When the RulesEngine attempts to evaluate a rule against properties that only exist in the 2nd or 3rd items, it fails because those properties were never added to the Dynamic Type definition.
Impact
Data Loss: Properties present in the JSON payload but missing from the first list item are dropped during the CreateObject mapping phase.
Rule Failures: Rules targeting optional fields will throw exceptions if the first record in the array happens to have that field as null.
Is there an existing mechanism or a preferred architectural pattern in the Rules Engine to control this behaviour?
If no alternative exists, I propose modifying this logic to iterate through the collection and build a "Master Schema" (a union of all keys found in the list). This ensures that the generated DynamicType contains every property necessary for rule evaluation, regardless of which item they appear in.
Beta Was this translation helpful? Give feedback.
All reactions