Evaluating object with List property

286 Views Asked by At

I try to evaluate this rule

<?xml version="1.0" encoding="utf-8"?>
<codeeffects
    xmlns="http://codeeffects.com/schemas/rule/41"
    xmlns:ui="http://codeeffects.com/schemas/ui/4">
    <rule id="PerformCalculation" webrule="5.0.9.6" utc="2020-11-23T13:13:42.3010" type="domain_product.Configs.WorkflowEngine.MicroflowModel, domain-product, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" eval="false">
        <definition>
            <if>
                <clause>
                    <rule id="40494eaf-4de0-4b3b-85b9-1c73473c2660" operator="doesNotExist">
                        <property name="e536c617_2636_47e8_93bb_66bb6c7fe3c0" />
                    </rule>
                </clause>
                <then>
                    <set>
                        <property name="775e6e9c_154f_45b3_9360_3d0a154ee19d" />
                        <value>test1</value>
                    </set>
                </then>
            </if>
        </definition>
        <format>
            <lines />
        </format>
    </rule>
    <rule id="40494eaf-4de0-4b3b-85b9-1c73473c2660" webrule="5.0.9.6" utc="2020-11-23T13:13:42.3010" type="transformify_template_api_factory_product.Domain.Model_cb958c7f_3681_40c5_573c_08d88fb1664f, DynamicAssembly.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" eval="true">
        <definition>
            <condition type="equal">
                <property name="Godini" />
                <value type="numeric">50</value>
            </condition>
        </definition>
        <format>
            <lines />
        </format>
    </rule>
</codeeffects>

The classes are

public class Model_710e265b_d07c_4c1b_573d_08d88fb1664f 
    {
        [Field(DisplayName = "Ime")]
        public string Ime { get; set; }

        [Field(DisplayName = "Prezime")]
        public string Prezime { get; set; }

        [Field(DisplayName = "Godini")]
        public int Godini { get; set; }
    }

public class MicroflowModel
    {
        [Field(DisplayName = "Variables -> Persons")]
        public List<Model_710e265b_d07c_4c1b_573d_08d88fb1664f> e536c617_2636_47e8_93bb_66bb6c7fe3c0{ get; set; }

        [Field(DisplayName = "Variables -> var1")]
        public string 775e6e9c_154f_45b3_9360_3d0a154ee19d { get; set; }
    }

The class Model_710e265b_d07c_4c1b_573d_08d88fb1664f is a part of an assembly called 'DynamicAssembly.dll' that is not loaded into the app-domain, but the class exists.

The class MicroflowModel is a part of a dynamically created assembly, and is generated with TypeBuilder.

When evaluating objects without List properties, the evaluation process is ok.

When evaluating objects with lists from the 'DynamicAssembly.dll' assembly (like in the example), the Evaluator constructor fails with this Message:

Value cannot be null. (Parameter 'type')

and StackTrace:

at System.Linq.Expressions.Expression.Validate(Type type, Boolean allowByRef)
   at System.Linq.Expressions.Expression.Parameter(Type type, String name)
   at CodeEffects.Rule.Core.ExpressionBuilderBase.BuildRule(XElement element)
   at CodeEffects.Rule.Core.ExpressionBuilderBase.Build(XElement element)
   at CodeEffects.Rule.Core.ExpressionBuilderBase.BuildIfRule(XElement element)
   at CodeEffects.Rule.Core.ExpressionBuilderBase.Build(XElement element)
   at CodeEffects.Rule.Core.ExpressionBuilderBase.Build(IEnumerable`1 elements)
   at CodeEffects.Rule.Core.ExpressionBuilderBase.GetSafeExpressionBody(XElement rule, Boolean addSourceNullCheck)
   at CodeEffects.Rule.Core.ExpressionBuilder.GetPredicateExpression(XElement rule)
   at CodeEffects.Rule.Core.Evaluator.CompileRule(XElement rule)
   at CodeEffects.Rule.Core.EvaluatorBase..ctor(Type sourceType, String rulesetXml, EvaluationParameters parameters, IFlexDataProvider provider)
   at CodeEffects.Rule.Core.Evaluator..ctor(Type sourceType, String rulesetXml, EvaluationParameters parameters)
   at ...

Please help

1

There are 1 best solutions below

1
On

You need to make that class available. The ExpressionBuilder must be able to load the type referenced in the internal rule (id="40494eaf-4de0-4b3b-85b9-1c73473c2660") using Type.GetType(), so as to build an expression tree.

Internally it calls

Type ruleType = Type.GetType("transformify_template_api_factory_product.Domain.Model_cb958c7f_3681_40c5_573c_08d88fb1664f, DynamicAssembly.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");

Since it can't find it, the result is null and the next call to Expression.Parameter() fails.