PrismLibrary/Prism · error · ArgumentNullException

propertyExpression

Error message

propertyExpression

What it means

PropertySupport.ExtractPropertyName throws ArgumentNullException when the 'propertyExpression' lambda is null. The method extracts a property name from an Expression<Func<T>>, so a null expression has no property to inspect.

Solutions

  1. Pass a valid member-access lambda such as () => this.SomeProperty
  2. Null-check the expression at your own helper boundary before forwarding
  3. Prefer nameof(SomeProperty) when compile-time name capture suffices (no expression needed)

Example fix

// before
var name = PropertySupport.ExtractPropertyName((Expression<Func<string>>)null);
// after
var name = PropertySupport.ExtractPropertyName(() => ViewModel.Title);
Defensive patterns

Strategy: type-guard

Validate before calling

if (propertyExpression == null)
    throw new ArgumentException("A property expression is required");

Type guard

bool IsPropertyExpression<T>(Expression<Func<T>> expr) =>
    expr != null && expr.Body is MemberExpression { Member: PropertyInfo };

Try / catch

try
{
    var name = PropertySupport.ExtractPropertyName(() => vm.Title);
}
catch (ArgumentNullException ex)
{
    logger.LogError(ex, "Property expression was null");
}

Prevention

When it happens

Trigger: Calling PropertySupport.ExtractPropertyName<T>(null) — usually when the expression came from a variable that was never assigned, or a helper method forwarded a null parameter.

Common situations: MVVM helpers computing property names for PropertyChanged notifications; generic base classes whose callers forgot to pass the expression.

Related errors


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

Appendix: source

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

    ///</summary>
    public static class PropertySupport
    {
        /// <summary>
        /// Extracts the property name from a property expression.
        /// </summary>
        /// <typeparam name="T">The object type containing the property specified in the expression.</typeparam>
        /// <param name="propertyExpression">The property expression (e.g. p => p.PropertyName)</param>
        /// <returns>The name of the property.</returns>
        /// <exception cref="ArgumentNullException">Thrown if the <paramref name="propertyExpression"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown when the expression is:<br/>
        ///     Not a <see cref="MemberExpression"/><br/>
        ///     The <see cref="MemberExpression"/> does not represent a property.<br/>
        ///     Or, the property is static.
        /// </exception>
        public static string? ExtractPropertyName<T>(Expression<Func<T>> propertyExpression)
        {
            if (propertyExpression == null)
                throw new ArgumentNullException(nameof(propertyExpression));

            return ExtractPropertyNameFromLambda(propertyExpression);
        }

        /// <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));

View on GitHub (pinned to 358118cd64)