microsoft / RulesEngine

A Json based Rules Engine with extensive Dynamic expression support
https://microsoft.github.io/RulesEngine/
MIT License
3.47k stars 528 forks source link

No applicable method 'IsNullOrWhiteSpace' exists in type 'String' #610

Closed RobbePeeters closed 1 week ago

RobbePeeters commented 2 weeks ago

We are currently building a validator using the RulesEngine in a .NET 8 project hosted in Azure container apps.

On of our rules is the following: string.IsNullOrWhiteSpace(Document.DocumentNumber) == false

When validating this rule in a unit test it succeeds without any problem. But when we run this in our docker-compose (local) or the deployed solution (container apps) we receive the following error: No applicable method 'IsNullOrWhiteSpace' exists in type 'String'

The running code is nothing to special: I have already tried passing 'string' as a custom type

var resettings = new ReSettings()
{
    CustomTypes = [typeof(string)]
};

var rulesEngine = new RulesEngine.RulesEngine([rule.Workflow], resettings);

var validationResult = await rulesEngine.ExecuteAllRulesAsync(rule.Workflow.WorkflowName,
    new RuleParameter("document", request.Data));

The dockerfile uses:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

... Followed by more COPY and RUN commands etc

Does anyone have an idea on what we might be doing wrong ?

timophe-91 commented 1 week ago

When i looked in the code static methods were not registered.

timophe-91 commented 1 week ago

Fixed it in my fork. The unit test is running fine

RobbePeeters commented 1 week ago

Hi @timophe-91, thanks for checking our issue out ! We found out that in our dynamic input 'Document.DocumentNumber' was sometimes empty. This causes the expression not to be resolved correctly throwing above exception as well.

Thanks !