Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior with UseFastExpressionCompiler = true when local param contains plus operator #608

Open
MinhNguyenDev opened this issue Jun 7, 2024 · 1 comment

Comments

@MinhNguyenDev
Copy link

How to reproduce:

Create a local param that is the calculation of 3 other local params, when UseFastExpressionCompiler flag set to false, the rule can run successfully, but when UseFastExpressionCompiler = true, it has an exception and failed :

    `var reSettingsWithCustomTypes = new ReSettings {
        UseFastExpressionCompiler = true
    };
    var rule = new Rule {
        RuleName = "check local param with plus operator",
        Expression = "Total > 0",
        LocalParams = new List<ScopedParam>() {
            new() {
                Name = "Field1",
                Expression = "AppData.Details.Sum(l => l.Amount)"
            },
            new() {
                Name = "Field2",
                Expression = "AppData.Details.Sum(l => l.Amount)"
            },
            new() {
                Name = "Field3",
                Expression = "AppData.Details.Sum(l => l.Amount)"
            },
            new() { Name = "Total", Expression = "Field1 + Field2 + Field3" },
        }
    };

    var worflow = new Workflow {
        WorkflowName = "UseFastExpressionCompilerTest",
        Rules = new[] { rule }
    };

    var input = new AppData() {
        Details = new() { new() { Amount = 1 }, new() { Amount = 2 }, new() { Amount = 3 }, }
    };

    var appData = new RuleParameter("AppData", input);

    var re = new RulesEngine(new[] { worflow }, reSettingsWithCustomTypes);
    var result = await re.ExecuteAllRulesAsync("UseFastExpressionCompilerTest", new[] { appData });

    Assert.Equal(true, result[0].IsSuccess);
}

public class AppData
{
    public List<Detail> Details { get; set; } = new List<Detail>();
}

public class Detail
{
    public decimal? Amount { get; set; }
}`

The exception was "Object reference not set to an instance of an object." in RuleCompiler

@asulwer
Copy link

asulwer commented Jun 20, 2024

in my testing

worked - remove nullable from your decimal property
worked - Expression = "AppData.Details.Sum(l => l.Amount.Value)" VALUE added

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

No branches or pull requests

2 participants