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

Question: No generic method 'Contains' on type 'System.Linq.Enumerable #178

Closed
fabich opened this issue Jun 28, 2018 · 3 comments
Closed

Comments

@fabich
Copy link

fabich commented Jun 28, 2018

Hi

I have the following issue:

System.InvalidOperationException: 'No generic method 'Contains' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. '

The code that I'm trying to run:

var s = = "@0.Contains(it.FkGenerickey)";
var list = new List<string> {"2736", "1903"};
var expression = DynamicExpressionParser.ParseLambda<TDTO, bool>(null, false, s, list)

I saw in other issues that the following code runs without any issues:

var result = testList.AsQueryable().Where("@0.Contains(it)", new List<string> { "a", "b" });

What am I missing?

@fabich fabich closed this as completed Jun 28, 2018
@fabich
Copy link
Author

fabich commented Jun 28, 2018

wrong type of list.
list needed to be List<int>

@StefH StefH changed the title No generic method 'Contains' on type 'System.Linq.Enumerable Question: No generic method 'Contains' on type 'System.Linq.Enumerable Jul 27, 2018
@oneillci
Copy link

oneillci commented Feb 2, 2021

I'm having this exact same issue using both approaches:

var predicate = "@0.Contains(instrumentId)";
var list = new List<int> { 1, 2 };
var expression = DynamicExpressionParser.ParseLambda<T, bool>(null, false, predicate, list);` // errors here
queryable = querable.Where(expression);

or

queryable = queryable.Where("@0.Contains(instrumentId)", new List<int> { 1, 2 });

Can you see anything I'm doing wrong?

Message: "No generic method 'Contains' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. "
Source: "System.Core"
StackTrace: " at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)\r\n at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments)\r\n at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseEnumerable(Expression instance, Type elementType, String methodName, Int32 errorPos, Type type) in C:\Users\azurestef\Documents\Github\zzzprojects\System.Linq.Dynamic.Core\src\System.Linq.Dynamic.Core\Parser\ExpressionParser.cs:line 1854

@oneillci
Copy link

oneillci commented Feb 2, 2021

Looked at this for a few hours and solved it minutes after posting the above - typical 😆

My issue is that my underlying type is a nullable int, so changing my list to this fixed it :)

var list = new List<int?> { 1, 2 };

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

No branches or pull requests

2 participants