When I am trying to compile the following code:
var post = iPostService.GetAll().Select(x => (x.Title, x.Author));
I get the compiler error: 'An expression tree may not contain a tuple literal.'
So I also tried this:
var post = iPostService.GetAll(). Select(x => new ValueTuple<string, string>(x.Title, x.Author))
The result is runtime error:'Cannot resolve method Void .ctor(System.String, System.String) because the declaring type of the method handle System.ValueTuple`2[T1,T2] is generic. Explicitly provide the declaring type to GetMethodFromHandle.'
I googled to find out the solution to this problem but nothing really helpful.
Any help really appreciated.
Finally, I found out what wrong with my code:
Hope it works with your code.
It works for me, create a tuple first and convert it to a ValueTupleï¼š
var post = iPostService.GetAll(). Select(x => new Tuple<string, string>(x.Title, x.Author).ToValueTuple())