PrismLibrary/Prism · error · ArgumentNullException
expression
Error message
expression
What it means
The internal helper ExtractPropertyNameFromLambda throws ArgumentNullException when the 'expression' LambdaExpression is null. It is called by ExtractPropertyName after the public null check, so it acts as a second line of defense for direct internal callers.
Solutions
- Ensure any LambdaExpression passed is non-null before the call
- Only use the public ExtractPropertyName<T> API, which performs its own null check
- Validate the upstream source of the expression (e.g. delegate resolution) can return null
Example fix
// before
PropertySupport.ExtractPropertyNameFromLambda(null);
// after
if (lambda != null)
PropertySupport.ExtractPropertyNameFromLambda(lambda); Defensive patterns
Strategy: type-guard
Validate before calling
if (lambda == null)
throw new ArgumentException("Lambda expression required"); Type guard
bool IsNonNullLambda(LambdaExpression? e) => e is not null;
Try / catch
try
{
var name = ExtractPropertyNameFromLambda(lambda);
}
catch (ArgumentNullException ex)
{
logger.LogError(ex, "Null lambda passed to property-name extractor");
} Prevention
- Call the public ExtractPropertyName<T> API rather than the internal helper
- Validate delegate/expression resolution results before use
- Avoid storing LambdaExpressions in mutable shared state
When it happens
Trigger: Internally passing a null LambdaExpression to ExtractPropertyNameFromLambda; race conditions where a shared expression variable is set to null between the public check and the internal call.
Common situations: Custom property-name utilities copied from Prism source; generic reflection helpers that resolve expressions at runtime and may yield null.
Related errors
- propertyExpression
- raiseErrorsChanged
- Resources.PropertySupport_ExpressionNotProperty_Exception
- Resources.PropertySupport_NotMemberAccessExpression_Exceptio…
- A dialog's ViewModel must implement the IDialogAware…
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/2f42a34feaaf352a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Mvvm/PropertySupport.cs:46
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));
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)