Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seq(1, 2, 3).AsQueryable().Count() fails #613

Merged
merged 3 commits into from
Jul 29, 2019

Conversation

StanJav
Copy link
Contributor

@StanJav StanJav commented Jul 24, 2019

Seq(1, 2, 3).AsQueryable().Count() fails because MS uses Type.IsValueType to check parameters for linq methods (e.g. Count) and that doesn't work for struct.

See this: https://referencesource.microsoft.com/#system.core/Microsoft/Scripting/Ast/TypeUtils.cs,164)

Exception details:

System.ArgumentException : Expression of type 'LanguageExt.Seq`1[System.Int32]' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[System.Int32]' of method 'Int32 Count[Int32](System.Collections.Generic.IEnumerable`1[System.Int32])'
Parameter name: arg0

at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
   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.EnumerableRewriter.VisitMethodCall(MethodCallExpression m)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.EnumerableExecutor`1.Execute()

StanJav and others added 2 commits July 24, 2019 16:19
Message: Expression of type 'LanguageExt.Seq`1[System.Int32]' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[System.Int32]' of method 'Int32 Count[Int32](System.Collections.Generic.IEnumerable`1[System.Int32])'

StackTrace: at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
   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.EnumerableRewriter.VisitMethodCall(MethodCallExpression m)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.EnumerableExecutor`1.Execute()
@StanJav StanJav closed this Jul 24, 2019
@StanJav
Copy link
Contributor Author

StanJav commented Jul 24, 2019

Sorry, closed for now. I am investigating one more very similar issue around IQueryable<T>.Freeze(). I will reopen later.

@StanJav StanJav reopened this Jul 29, 2019
@StanJav
Copy link
Contributor Author

StanJav commented Jul 29, 2019

@louthy I have added Enumerable & Queryable extensions for Lst, Set, Arr, Seq. It is ready for a review.

@louthy louthy merged commit eaa02a6 into louthy:master Jul 29, 2019
@louthy
Copy link
Owner

louthy commented Jul 29, 2019

Thanks @StanJav - I'm still in London, but I'll probably head back this evening and be able to deploy to nu-get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants