DelegateDecompiler
DelegateDecompiler copied to clipboard
Decompile fails when calling Enumerable.LastOrDefault
This scenario fails to decompile with version 0.20
.
public class Test {
public string A { get; set; }
}
public class Test2 {
public List<Test> Colleciton { get; } = new List<Test>();
[Decompileable]
public Test Last => Collection.LastOrDefault();
}
The exception stack trace (translated partially from hungarian)
System.ArgumentException: The following method contains generic parameters: System.Collections.Generic.List`1[Test] get_Collection().
a következő helyen: System.Linq.Expressions.Expression.ValidateMethodInfo(MethodInfo method)
a következő helyen: System.Linq.Expressions.Expression.Property(Expression expression, MethodInfo propertyAccessor)
a következő helyen: DelegateDecompiler.Processor.BuildMethodCallExpression(MethodInfo m, Address instance, Expression[] arguments)
a következő helyen: DelegateDecompiler.Processor.Call(ProcessorState state, MethodInfo m)
a következő helyen: DelegateDecompiler.Processor.Process()
a következő helyen: DelegateDecompiler.Processor.Process(VariableInfo[] locals, IList`1 args, Instruction instruction, Type returnType)
a következő helyen: DelegateDecompiler.MethodBodyDecompiler.Decompile()
a következő helyen: DelegateDecompiler.DecompileExtensions.<>c__DisplayClass2_0.<Decompile>b__0(MethodInfo m)
a következő helyen: DelegateDecompiler.Cache`2.GetOrAdd(TKey key, Func`2 func)
a következő helyen: DelegateDecompiler.DecompileExtensions.Decompile(MethodInfo method)
a következő helyen: DelegateDecompiler.DecompileExpressionVisitor.Decompile(MethodInfo method, Expression instance, IList`1 arguments)
a következő helyen: DelegateDecompiler.DecompileExpressionVisitor.VisitMember(MemberExpression node)
a következő helyen: System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
a következő helyen: System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
a következő helyen: DelegateDecompiler.DecompileExpressionVisitor.Decompile(Expression expression)
@cervengoc what versions of .NET and VS do you use?
.NET 4.5 VS2015 Win8.1 x64
The reason I'm asking is because I could not reproduce the error. Can you provide a test case which is failing?
I'll try to break it down when I have some time.
Pretty sure Linq to SQL doesnt support last() because theres no such SQL query?
@lindeberg You''re likely right, but not every LINQ expression will end up into an SQL query :) If I remember correctly this particularly was used in the context of a Javascript code-generator.
Could not reproduce. See #196