Skip to content

Conversation

@thibault-reigner
Copy link
Contributor

Issue

Currently, when trying to parse with `DynamicExpressionParser an expression container an indexed property with more than 1 index, it would throw with the following exception (cf. added unit test illustrating the issue)

System.ArgumentException: Incorrect number of arguments supplied for call to method 'System.String get_Item(Int32, System.String)' (Parameter 'method'...

System.ArgumentException
Incorrect number of arguments supplied for call to method 'System.String get_Item(Int32, System.String)' (Parameter 'method')
   at System.Dynamic.Utils.ExpressionUtils.ValidateArgumentCount(MethodBase method, ExpressionType nodeKind, Int32 count, ParameterInfo[] pis)
   at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression arg0)
   at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseElementAccess(Expression expr) in /Users/thibault/Code/System.Linq.Dynamic.Core/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs:line 2369

The fix is rather straightforward, consisting in removing the hardcoded assumption that .NET indexer can't have more than 1 index parameter.

@thibault-reigner thibault-reigner changed the title [Bug fix] DynamicExpressionParser - Handle indexed properties with any number of indices in expression DynamicExpressionParser - Handle indexed properties with any number of indices in expression Oct 10, 2025
@StefH StefH requested a review from Copilot October 10, 2025 12:00
@StefH StefH added the bug label Oct 10, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the DynamicExpressionParser where indexed properties with multiple indices would throw an ArgumentException. The parser was incorrectly assuming that indexers could only have a single parameter, causing failures when trying to access multi-dimensional indexers.

  • Replaced hardcoded single-parameter indexer logic with dynamic parameter handling
  • Added proper type conversion for each indexer parameter
  • Added comprehensive test coverage for both single and multi-dimensional indexers

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs Updated ParseElementAccess method to handle indexers with any number of parameters
test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs Added test class and test methods to verify multi-dimensional indexer functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants