Skip to content

Issue finding indexer #57

@richardsheppard-avalara

Description

@richardsheppard-avalara

I'm running into an issue with the .Net Core port of dynamic linq.

I'm trying to sort a list of JObjects and I get this error:

No applicable indexer exists in type 'JObject'.

Here's an example

var rows = new List<JObject>();

var row1 = new JObject();
row1["Column1"] = "B";
row1["Column2"] = 2;
rows.Add(row1);

var row2 = new JObject();
row2["Column1"] = "B";
row2["Column2"] = 1;
rows.Add(row2);

var row3 = new JObject();
row3["Column1"] = "A";
row3["Column2"] = 2;
rows.Add(row3);

var row4 = new JObject();
row4["Column1"] = "A";
row4["Column2"] = 1;
rows.Add(row4);

var list = rows.AsQueryable().OrderBy(@"it[""Column1""]").ToList();

Note this code works with the System.Linq.Dynamic dll on a .Net 4.5.2 project.

I believe this issue resides in the FindIndexer method in the ExpressionParser class.

https://github.com/StefH/System.Linq.Dynamic.Core/blob/master/src/System.Linq.Dynamic.Core/ExpressionParser.cs#L1681-L1707

        int FindIndexer(Type type, Expression[] args, out MethodBase method)
        {
            foreach (Type t in SelfAndBaseTypes(type))
            {
#if !(NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
                MemberInfo[] members = t.GetDefaultMembers();
#else
                MemberInfo[] members = new MemberInfo[0];
#endif

If you take away the NETSTANDARD check everything seems to work, although I'm not sure if that would effect anything else. I made that change locally and ran all the unit tests and they all passed. There might be better fix, but I'm not as familiar with the code.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions