Repository: dotnet/aspnetcore
File: src/Components/Forms/src/FieldIdentifier.cs (C#)

Code before:

        var result = accessor(value);
        return result;

        [UnconditionalSuppressMessage(
            "Trimming",
            "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
            Justification = "Application code does not get trimmed. We expect the members in the expression to not be trimmed.")]
        static Func<object, object> CreateAccessor((Type model, MemberInfo member) arg)
        {
            var parameter = Expression.Parameter(typeof(object), "value");
            Expression expression = Expression.Convert(parameter, arg.model);

            expression = Expression.MakeMemberAccess(expression, arg.member);
            expression = Expression.Convert(expression, typeof(object));
            var lambda = Expression.Lambda<Func<object, object>>(expression, parameter);

            var func = lambda.Compile();
            return func;
        }
    }

    private static object GetModelFromIndexer(Expression methodCallExpression)
    {
        object model;
        var methodCallObjectLambda = Expression.Lambda(methodCallExpression!);
        var methodCallObjectLambdaCompiled = (Func<object?>)methodCallObjectLambda.Compile();
        var result = methodCallObjectLambdaCompiled();
        if (result is null)
        {
            throw new ArgumentException("The provided expression must evaluate to a non-null value.");
        }
        model = result;
        return model;
    }

    private static void ClearCache()
    {
        _fieldAccessors.Clear();
    }
}


Review comment (suggestion):
```suggestion
        var methodCallObjectLambda = Expression.Lambda(typeof(Func<object?>), methodCallExpression!);
```

Code after:

        var result = accessor(value);
        return result;

        [UnconditionalSuppressMessage(
            "Trimming",
            "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
            Justification = "Application code does not get trimmed. We expect the members in the expression to not be trimmed.")]
        static Func<object, object> CreateAccessor((Type model, MemberInfo member) arg)
        {
            var parameter = Expression.Parameter(typeof(object), "value");
            Expression expression = Expression.Convert(parameter, arg.model);

            expression = Expression.MakeMemberAccess(expression, arg.member);
            expression = Expression.Convert(expression, typeof(object));
            var lambda = Expression.Lambda<Func<object, object>>(expression, parameter);

            var func = lambda.Compile();
            return func;
        }
    }

    private static object GetModelFromIndexer(Expression methodCallExpression)
    {
        object model;
        var methodCallObjectLambda = Expression.Lambda(typeof(Func<object?>), methodCallExpression!);
        var methodCallObjectLambdaCompiled = (Func<object?>)methodCallObjectLambda.Compile();
        var result = methodCallObjectLambdaCompiled();
        if (result is null)
        {
            throw new ArgumentException("The provided expression must evaluate to a non-null value.");
        }
        model = result;
        return model;
    }

    private static void ClearCache()
    {
        _fieldAccessors.Clear();
    }
}