lundi 9 mai 2022

C# Reflection Invalid Cast Exception

I am getting the following error from the C# code below.

public static PropertyInfo GetPropertyInfo<T, T2>(this Expression<Func<T, T2>> propertyLambda)
{
    var member = propertyLambda.Body as MemberExpression
        ?? ((UnaryExpression)propertyLambda.Body).Operand as MemberExpression;    
}

System.InvalidCastException : Unable to cast object of type 'System.Linq.Expressions.MethodCallExpressionN' to type 'System.Linq.Expressions.UnaryExpression'

Attached is the front end code in MVC which gets called to this C# code

.AddControl(x => x.SipKpiCriteria.Select(y => y.EvaluationMethod).FirstOrDefault())




Aucun commentaire:

Enregistrer un commentaire