DelegateDecompiler icon indicating copy to clipboard operation
DelegateDecompiler copied to clipboard

Decompile fails when calling Enumerable.LastOrDefault

Open cervengoc opened this issue 7 years ago • 6 comments

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 avatar Dec 19 '16 12:12 cervengoc

@cervengoc what versions of .NET and VS do you use?

hazzik avatar Dec 19 '16 22:12 hazzik

.NET 4.5 VS2015 Win8.1 x64

cervengoc avatar Dec 20 '16 02:12 cervengoc

The reason I'm asking is because I could not reproduce the error. Can you provide a test case which is failing?

hazzik avatar Dec 20 '16 02:12 hazzik

I'll try to break it down when I have some time.

cervengoc avatar Jan 02 '17 12:01 cervengoc

Pretty sure Linq to SQL doesnt support last() because theres no such SQL query?

lindeberg avatar Sep 22 '18 15:09 lindeberg

@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.

cervengoc avatar Sep 22 '18 18:09 cervengoc

Could not reproduce. See #196

hazzik avatar Oct 13 '22 04:10 hazzik