PrismLibrary/Prism · error · ArgumentException

Resources.PropertySupport_NotMemberAccessExpression_Exceptio…

Error message

Resources.PropertySupport_NotMemberAccessExpression_Exception

What it means

ExtractPropertyNameFromLambda throws ArgumentException with PropertySupport_NotMemberAccessExpression_Exception when the lambda body is not a MemberExpression — e.g. () => someMethod(), () => 1 + 2, or () => a + b. Only direct property accesses like () => obj.Property can be resolved to a property name.

Solutions

  1. Pass a pure property-access lambda: () => instance.PropertyName
  2. If you need a name for a method or computed value, use nameof() instead
  3. Verify the lambda body compiles to MemberExpression with MemberTypes.Property

Example fix

// before
var name = PropertySupport.ExtractPropertyName(() => GetFullName()); // method call
// after
var name = PropertySupport.ExtractPropertyName(() => Person.FullName); // property access
Defensive patterns

Strategy: validation

Validate before calling

if (expr.Body is not MemberExpression)
    throw new ArgumentException("Expression must be a property access like () => obj.Prop");

Type guard

bool IsPropertyAccess<T>(Expression<Func<T>> expr) =>
    expr?.Body is MemberExpression;

Try / catch

try
{
    var name = PropertySupport.ExtractPropertyName(expr);
}
catch (ArgumentException ex) when (ex.Message.Contains("member access"))
{
    logger.LogError(ex, "Expression {0} is not a property access", expr);
}

Prevention

When it happens

Trigger: Passing () => SomeMethod(), () => localVariable, () => field + 1, or any computed expression to PropertySupport.ExtractPropertyName.

Common situations: Developers assuming any lambda works and passing method calls; capturing values in closures and passing the closure expression; using expression-bodied helpers that return computed values.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/0d102e658fba404d. Report an issue: GitHub.

Appendix: source

Thrown at src/Prism.Core/Mvvm/PropertySupport.cs:50

        /// <summary>
        /// Extracts the property name from a LambdaExpression.
        /// </summary>
        /// <param name="expression">The LambdaExpression</param>
        /// <returns>The name of the property.</returns>
        /// <exception cref="ArgumentNullException">Thrown if the <paramref name="expression"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown when the expression is:<br/>
        ///     The <see cref="MemberExpression"/> does not represent a property.<br/>
        ///     Or, the property is static.
        /// </exception>
        internal static string? ExtractPropertyNameFromLambda(LambdaExpression expression)
        {
            if (expression == null)
                throw new ArgumentNullException(nameof(expression));

            var memberExpression = expression.Body as MemberExpression;
            if (memberExpression == null)
                throw new ArgumentException(Resources.PropertySupport_NotMemberAccessExpression_Exception, nameof(expression));

            var property = memberExpression.Member as PropertyInfo;
            if (property == null)
                throw new ArgumentException(Resources.PropertySupport_ExpressionNotProperty_Exception, nameof(expression));

            var getMethod = property.GetMethod;
            if (getMethod.IsStatic)
                throw new ArgumentException(Resources.PropertySupport_StaticExpression_Exception, nameof(expression));

            return memberExpression.Member.Name;
        }

    }
}

View on GitHub (pinned to 358118cd64)