Skip to content

1.4.7 Regression -- NullReferenceException from invalid expression instead of ArgumentException #849

@rbell517

Description

@rbell517

1. Description

In versions 1.4.6 and previous giving invalid expressions would throw ArgumentException or ArgumentNullException, which we could handle accordingly. Instead now a NullReferenceException is thrown, which is bad practice to throw and bad practice to catch.

2. Exception

Exception message: System.NullReferenceException: Object reference not set to an instance of an object.
Stack trace:
   at System.Linq.Dynamic.Core.Parser.ExpressionHelper.GenerateStaticMethodCall(String methodName, Expression left, Expression right)
   at System.Linq.Dynamic.Core.Parser.ExpressionHelper.GenerateGreaterThanEqual(Expression left, Expression right)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda[T,TResult](ParsingConfig parsingConfig, Boolean createParameterCtor, String expression, Object[] values)

3. Fiddle or Project

https://dotnetfiddle.net/sjyNPf

This example uses a numeric operator on a string type, which is invalid and should throw an ArgumentException, but instead throws a NullReferenceException.

Change the nuget version to 1.4.6 to see the expected exception

4. Any further technical details

Valid expressions do not show any regressions.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions