Eval-Expression.NET
Eval-Expression.NET copied to clipboard
cast / parentheses causing null coalescing usage failure
stripped down to a relatively minimal block to show the issue.
error: Oops! No applicable member has been found for the expression. The error occurred for expression "?." at position 59 near "?.ToString(\"g\");
const string mutationScript = """
// throws exception
dict["CreatedOn"] = ((DateTime?)dict["CreatedOn"])?.ToString("g");
// works
// dict["CreatedOn"] = dict["CreatedOn"]?.ToString("g");
""";
var dicts = new[] {
new Dictionary<string, object>()
{
{ "CreatedOn", DateTime.Now }
},
new Dictionary<string, object>()
{
{ "CreatedOn", null }
}
};
var evalContext = new EvalContext
{
SafeMode = true
};
evalContext.UnregisterAll();
evalContext.RegisterDefaultAliasSafe();
evalContext.RegisterType(
typeof(IDictionary<string, object>),
typeof(string),
typeof(DateTime?)
);
var compiled = evalContext.Compile<Action<IDictionary<string, object>>>(
mutationScript,
"dict"
);
foreach(var dict in dicts) {
compiled(dict);
}
Hello @mrtristan ,
Thank you for reporting; I can confirm I successfully reproduced this issue with your code, so we will look at it.
Best Regards,
Jon
Hello @mrtristan ,
The v6.1.4 has been released.
Could you let us know if my developer fixed the issue correctly?
Best Regards,
Jon