PrismLibrary/Prism · error · ArgumentException
Resources.PropertySupport_ExpressionNotProperty_Exception
Error message
Resources.PropertySupport_ExpressionNotProperty_Exception
What it means
ExtractPropertyNameFromLambda throws ArgumentException with PropertySupport_ExpressionNotProperty_Exception when the lambda body is a member access but that member is a FieldInfo rather than a PropertyInfo. Prism only supports properties, since the helper is meant for PropertyChanged scenarios.
Solutions
- Convert the field to a property and pass () => instance.PropertyName
- Use nameof(fieldName) if you genuinely need a field's name — nameof requires no expression
- If you cannot change the type, wrap the field in a property first
Example fix
// before
public string Name; // field
var name = PropertySupport.ExtractPropertyName(() => instance.Name); // throws
// after
public string Name { get; set; } // property
var name = PropertySupport.ExtractPropertyName(() => instance.Name); // ok Defensive patterns
Strategy: validation
Validate before calling
if (expr.Body is MemberExpression me && me.Member is not PropertyInfo)
throw new ArgumentException("Use a property, not a field, in the expression"); Type guard
bool IsFieldAccess<T>(Expression<Func<T>> expr) =>
(expr?.Body as MemberExpression)?.Member is FieldInfo; Try / catch
try
{
var name = PropertySupport.ExtractPropertyName(() => obj.Name);
}
catch (ArgumentException ex)
{
logger.LogError(ex, "Expression must target a property, not a field");
} Prevention
- Replace public fields with auto-properties (migrates transparently)
- Avoid passing compiler-generated or interop fields to expression helpers
- Document that Prism's helper supports properties only
When it happens
Trigger: Passing () => someField (a public field, not a property) to PropertySupport.ExtractPropertyName.
Common situations: Legacy codebases with public fields used where properties belong; structs/DTOs exposing fields; interop types surfaced as fields (e.g. COM interop or compiler-generated backing fields).
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
- Resources.PropertySupport_NotMemberAccessExpression_Exceptio…
- expression
- propertyExpression
- A dialog's ViewModel must implement the IDialogAware…
- A dialog's ViewModel must implement the IDialogAware…
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/ac70ee9369f3a24e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Mvvm/PropertySupport.cs:54
/// <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)