RulesEngine icon indicating copy to clipboard operation
RulesEngine copied to clipboard

Common Language Runtime error

Open solutions-simplified opened this issue 2 years ago • 4 comments

I recently upgrade from 4.0.0 to 5.0.1. I am getting errors across the board and it looks like it's related to the breaking change in 5.0.0. In my Utils class I have static methods that take in strongly typed objects (see below). I keep getting a Common Language Runtime error when these rules execute. It appears to be because it can't actually execute my method in the Utils class. Suggestions?

I reviewed the Wiki but the examples shown with Utils is simple string parameters, but do not see any examples with extension methods utilizing strongly typed objects. If I lower back to 4.0.0 everything works as expected.

My expression: customers.Where(CreatedDate >= createdFilterParameter).Where(Utils.IsExistingEmail(Emails, newCustomerDataParameter)).Count() < threshold

public static class Utils
{
    public static bool IsExistingEmail(ICollection<Email> emails, Customer customer)
    {
        if (emails is null || customer is null)
            return false;
			
			
	return emails.Any(x => x.Address.Contains(customer.Email));
    }
}	

Thank you in advance for any suggestions - this library is awesome :)

solutions-simplified avatar Aug 01 '23 12:08 solutions-simplified

can you provide me details on how you pass inputs to RulesEngine? Also can you try if AutoRegisterInputType = false in ReSettings helps mitigate the issue?

abbasc52 avatar Aug 02 '23 12:08 abbasc52

@abbasc52 here is what I currently have.

var ruleParameters = new RuleParameter[] { new RuleParameter("emails", emailsDataset), new RuleParameter("customer", newCustomer) };

var rulesEngine = new RulesEngine( new Workflow[] { workflow }, new ReSettings { CustomTypes = new Type[] { typeof(Utils) }});

var ruleResults = await rulesEngine.ExecuteAllRulesAsync(workflow.Name, ruleParameters);

solutions-simplified avatar Aug 03 '23 15:08 solutions-simplified

@abbasc52 I wanted to follow up on this - any suggestions :)

solutions-simplified avatar Aug 07 '23 19:08 solutions-simplified

@solutions-simplified I assume your customer input is of Type Customer. There is a bug in our dependent lib where if the names are same for input and type(even if case are different), uses the type instead of input.

I am working with the lib to fix this issue, but meanwhile u can use try the below fixes:

  • Simplest solution would be to rename the input param to not match the class name.
  • Other option is to disable autotypeRegister. new ReSettings { CustomTypes = new Type[] { typeof(Utils) }}, AutoRegisterInputType : false );

abbasc52 avatar Aug 08 '23 09:08 abbasc52