Optional parameters for method calls not supported by expression evaluation
まだ誰も着手していません。
評価
調査の方向性
まず、PdfAttachmentValidator と省略されたオプション引数を使って式を再現し、次に LambdaExpressionBuilder.BuildDelegateForRule とスタックトレースに記載された RuleCompiler のエントリポイントを調べます。式がコンパイルされ、オプションパラメーターを明示的に渡さずに PdfContentContainsSubstring("Mahnung") を呼び出し、このケースのリグレッションカバレッジが追加されていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
STR
Define a rule as following:
{
"RuleName": "TestPdfAttachmentContent1",
"Expression": "pdfAttachments[0].PdfContentContainsSubstring(\"Mahnung\")"
}
(That input/RuleParameter is of course defined, it's not what matters here.)
If I catch all CLR exceptions while debugging, I get the following exception:
RulesEngine.Exceptions.RuleException
HResult=0x80131500
Nachricht = Error while compiling rule `TestPdfAttachmentContent1`: No applicable method 'PdfContentContainsSubstring' exists in type 'PdfAttachmentValidator'
Quelle = RulesEngine
Stapelüberwachung:
bei RulesEngine.HelperFunctions.Helpers.HandleRuleException(Exception ex, Rule rule, ReSettings reSettings)
Diese Ausnahme wurde ursprünglich von dieser Aufrufliste ausgelöst:
RulesEngine.HelperFunctions.Helpers.HandleRuleException(System.Exception, RulesEngine.Models.Rule, RulesEngine.Models.ReSettings)
RulesEngine.ExpressionBuilders.LambdaExpressionBuilder.BuildDelegateForRule(RulesEngine.Models.Rule, RulesEngine.Models.RuleParameter[])
RulesEngine.RuleCompiler.BuildRuleFunc(RulesEngine.Models.Rule, RulesEngine.Models.RuleParameter[])
RulesEngine.RuleCompiler.GetDelegateForRule(RulesEngine.Models.Rule, RulesEngine.Models.RuleParameter[])
RulesEngine.RuleCompiler.CompileRule(RulesEngine.Models.Rule, RulesEngine.Models.RuleExpressionType, RulesEngine.Models.RuleParameter[], System.Lazy<RulesEngine.Models.RuleExpressionParameter[]>)
Innere Ausnahme 1:
ParseException: No applicable method 'PdfContentContainsSubstring' exists in type 'PdfAttachmentValidator'
Not, however, and this is a general behavior I don't quite like the exception is silently ignored even though I have explicitly disabled EnableExceptionAsErrorMessage (see below).
Note this is not true, because the PdfAttachmentValidator has such a method, but with an optional second argument:
public class PdfAttachmentValidator
{
public bool PdfContentContainsSubstring(string substring, bool caseInsensitive = true)
{
return true;
}
}
And yes, I've obviously injected the type:
var engineSettings = new ReSettings()
{
CustomActions = // ...
CustomTypes =
[
typeof(PdfAttachmentValidator)
],
EnableExceptionAsErrorMessage = false
};
new RulesEngine.RulesEngine(mailWorkflows, engineSettings);
What happens
Apparently, it cannot find PdfContentContainsSubstring("Mahnung") as it cannot find the method signature PdfContentContainsSubstring(string substring, bool caseInsensitive = true).
What should happen
Just call PdfContentContainsSubstring with PdfContentContainsSubstring("Mahnung"), ignoring the optional parameter.
Workaround
Changing it like this and passing the optional parameter explicitly, makes it magically work:
{
"RuleName": "TestPdfAttachmentContent1",
"Expression": "pdfAttachments[0].PdfContentContainsSubstring(\"Mahnung\", true)"
}
But this is superfluous, obviously. And I would like to avoid this for obvious reasons.
More information
Weirdly enough, even changing it to default does not work (for whatever reason):
{
"RuleName": "TestPdfAttachmentContent1",
"Expression": "pdfAttachments[0].PdfContentContainsSubstring(\"Mahnung\", default)"
}
The (handled) exception then is Unknown identifier 'default':
RulesEngine.Exceptions.RuleException
HResult=0x80131500
Nachricht = Error while compiling rule `TestPdfAttachmentContent1`: Unknown identifier 'default'
Quelle = RulesEngine
Stapelüberwachung:
bei RulesEngine.HelperFunctions.Helpers.HandleRuleException(Exception ex, Rule rule, ReSettings reSettings)
bei RulesEngine.HelperFunctions.Helpers.ToRuleExceptionResult(ReSettings reSettings, Rule rule, Exception ex)
bei RulesEngine.RuleCompiler.CompileRule(Rule rule, RuleExpressionType ruleExpressionType, RuleParameter[] ruleParams, Lazy`1 globalParams)
bei RulesEngine.RulesEngine.CompileRule(Rule rule, RuleExpressionType ruleExpressionType, RuleParameter[] ruleParams, Lazy`1 scopedParams)
bei RulesEngine.RulesEngine.CompileRule(String workflowName, String ruleName, RuleParameter[] ruleParameters)
bei RulesEngine.RulesEngine.<ExecuteActionWorkflowAsync>d__13.MoveNext()
Diese Ausnahme wurde ursprünglich von dieser Aufrufliste ausgelöst:
RulesEngine.HelperFunctions.Helpers.HandleRuleException(System.Exception, RulesEngine.Models.Rule, RulesEngine.Models.ReSettings)
RulesEngine.ExpressionBuilders.LambdaExpressionBuilder.BuildDelegateForRule(RulesEngine.Models.Rule, RulesEngine.Models.RuleParameter[])
RulesEngine.RuleCompiler.BuildRuleFunc(RulesEngine.Models.Rule, RulesEngine.Models.RuleParameter[])
RulesEngine.RuleCompiler.GetDelegateForRule(RulesEngine.Models.Rule, RulesEngine.Models.RuleParameter[])
RulesEngine.RuleCompiler.CompileRule(RulesEngine.Models.Rule, RulesEngine.Models.RuleExpressionType, RulesEngine.Models.RuleParameter[], System.Lazy<RulesEngine.Models.RuleExpressionParameter[]>)
Innere Ausnahme 1:
ParseException: Unknown identifier 'default'
System
<TargetFramework>net8.0</TargetFramework>
<!-- ... -->
<PackageReference Include="RulesEngine" Version="5.0.3" />
aka .NET 8
Windows 10
- 主要言語
- C#
- スター
- 4.4k
- フォーク
- 616
- 平均マージ
- 6分
- マージ済み PR(30日)
- 2
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/RulesEngine のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
microsoft/RulesEngine#747 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
microsoft/RulesEngine#702 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
microsoft/RulesEngine#701 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
microsoft/RulesEngine#700 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
microsoft/RulesEngine#699 ·
microsoft/RulesEngine の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
dotnet/AspNetCore.Docs#37699 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
SubtitleEdit/subtitleedit#15108 · コメント 1 件 ·
-
area/docs-content Bug pulumi/docs
難易度 1/5 1〜3時間 初心者へのやさしさ 94/100
-
agentic-workflows untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100