Skip to content

Strange SelectMany behaviour using JSON #511

@toarnold

Description

@toarnold

1. Description

Combining multiple arrays with a sSelectMany and an unconditioned sub-select throws an IndexOutOfRange exception. Appending a condition will do the trick.

2. Exception

Exception message: IndexOutOfRangeException: Index was outside the bounds of the array.
Stack trace:

   at System.Linq.Dynamic.Core.DynamicQueryableExtensions.SelectManyInternal(IQueryable source, ParsingConfig config, Type resultType, String selector, Object[] args)
   at System.Linq.Dynamic.Core.DynamicQueryableExtensions.SelectMany(IQueryable source, String selector, Object[] args)
   at ConsoleApp1.Program.TestJarray() in D:\BluePrism\ConsoleApp1\ConsoleApp1\Program.cs:line 58
   at ConsoleApp1.Program.Main(String[] args) in D:\BluePrism\ConsoleApp1\ConsoleApp1\Program.cs:line 79

3. Fiddle or Project

            var array1 = JArray.Parse("[1,2,3]");
            var array2 = JArray.Parse("[4,5,6]");

            // This simple Linq query works!
            var result1 = new[] { array1, array2 }.SelectMany(x => x);

            // This throws the exception. Expected same result as line above!
            var result2 = new[] { array1, array2 }.AsQueryable().SelectMany("it");

            // No Exception. The condition will do the trick!
            var result3 = new[] { array1, array2 }.AsQueryable().SelectMany("it.Where(true)");

4. Any further technical details

This exception will occurs, if the array if a property of an JSON object, too.
In contrast a simple Select instead of SelectMany works properly, but isn't intended.

            // This works!
            var result2 = new[] { array1, array2 }.AsQueryable().Select("it");

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions