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] Enumerable.Range(0,10).Select() not working #84

Closed
jlvuolle opened this issue Feb 18, 2021 · 1 comment
Closed

[question] Enumerable.Range(0,10).Select() not working #84

jlvuolle opened this issue Feb 18, 2021 · 1 comment

Comments

@jlvuolle
Copy link

Hi,

I am trying to execute following kind of expression

evaluator.Evaluate("Enumerable.Range(0, 10).Select(x => x * x)");

but I get following error for it:

CodingSeb.ExpressionEvaluator.ExpressionEvaluatorSyntaxErrorException: '[System.Linq.Enumerable+d__113] object has no Method named "Select".'

Interesting part is that this works in LINQPad (.NET Core 3.1.8) but not within Visual Studio (.NET Framework 4.7.2).

If I run following code in VS:

var result_a = Enumerable.Range(0, 10);
var result_b = evaluator.Evaluate("Enumerable.Range(0, 10)");

I can see that both variables have value
System.Linq.Enumerable.<RangeIterator>d__113}
but different types:

result_a: System.Collections.Generic.IEnumerable<int> {System.Linq.Enumerable.<RangeIterator>d__113}
result_b: object {System.Linq.Enumerable.<RangeIterator>d__113}

I don't get what is going on here and why it works in LINQPad but not in VS. Any hints?

@jlvuolle
Copy link
Author

Found the trick: you have to use Cast(). So

evaluator.Evaluate("Enumerable.Range(0, 10).Cast().Select(x => x * x)");

works nicely. Case closed.

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

No branches or pull requests

1 participant