And I possibly found the root cause and fix, in class Remotion.Linq.Clauses.ExpressionTreeVisitors.AccessorFindingExpressionTreeVisitor, the method GetMemberAccessExpression should check if the input expression is the member’s declaring type (or subclass of declaring type), and do a conversion when necessary. Of course I could be wrong, or perhaps there's other more elegant way to fix.
private Expression GetMemberAccessExpression (Expression input, MemberInfo member)
{
// This is the fix part <<
if (!member.DeclaringType.GetTypeInfo().IsAssignableFrom(input.Type.GetTypeInfo()))
{
input = Expression.Convert(input, member.DeclaringType);
}
// >> This is the fix part
var methodInfo = member as MethodInfo;
if (methodInfo != null)
return Expression.Call (input, methodInfo);
else
return Expression.MakeMemberAccess (input, member);
}
Best regards,
Ray