PrismLibrary/Prism · error · NotSupportedException
Operation not supported for the given expression type. Only…
Error message
Operation not supported for the given expression type. Only MemberExpression and ConstantExpression are currently supported.
What it means
PropertyObserver builds a subscription chain from a property expression like () => obj.A.B, but it only understands MemberExpression and ConstantExpression nodes. Passing any other expression kind (method calls, binary expressions, conversions beyond member chains) causes this NotSupportedException.
Solutions
- Rewrite the lambda as a plain member chain ending at a field/property of a concrete object, e.g. () => vm.Inner.Name
- Evaluate the intermediate value yourself and observe the resulting object's property
- Subscribe manually to PropertyChanged for non-member-chain scenarios
Example fix
// before PropertyObserver.Create(() => vm.CalculateTotal().Amount); // after PropertyObserver.Create(() => vm.TotalAmount);
Defensive patterns
Strategy: validation
Validate before calling
var body = ((LambdaExpression)expr).Body; bool ok = body is MemberExpression || body is ConstantExpression; // only pass expressions whose body is a member/constant chain
Type guard
static bool IsSupportedPropertyExpression<T>(Expression<Func<T>> e) => e.Body is MemberExpression || e.Body is ConstantExpression;
Try / catch
try { observer = PropertyObserver.Create(expr); }
catch (NotSupportedException) { /* fall back to manual PropertyChanged subscription */ } Prevention
- Use only plain member-chain lambdas: () => a.B.C
- Avoid method calls, operators, or casts inside observed expressions
- Inspect the expression body type before handing it to PropertyObserver
When it happens
Trigger: Calling PropertyObserver.Create(() => x.GetFoo().Bar), (() => a + b), or any lambda whose body is not a chain of member accesses ending in a constant root; thrown from SubscribeListeners during observation setup.
Common situations: Developers try to observe computed properties via method calls or use expression bodies with operators, assuming arbitrary expression trees are supported.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Tried to subscribe to PropertyChanged in the object that…
- propertyInfo
- Tried to subscribe to PropertyChanged in the object that…
- IModuleCatalog was null
- The page type ' ' is not supported.
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/48c8fa5d0f8aa9ab.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Commands/PropertyObserver.cs:38
_action = action;
SubscribeListeners(propertyExpression);
}
private void SubscribeListeners(Expression? propertyExpression)
{
var propNameStack = new Stack<PropertyInfo>();
while (propertyExpression is MemberExpression temp) // Gets the root of the property chain.
{
propertyExpression = temp.Expression;
if (temp.Member is PropertyInfo propertyInfo)
{
propNameStack.Push(propertyInfo); // Records the member info as property info
}
}
if (propertyExpression is not ConstantExpression constantExpression)
throw new NotSupportedException("Operation not supported for the given expression type. " +
"Only MemberExpression and ConstantExpression are currently supported.");
var propObserverNodeRoot = new PropertyObserverNode(propNameStack.Pop(), _action);
PropertyObserverNode previousNode = propObserverNodeRoot;
foreach (var propName in propNameStack) // Create a node chain that corresponds to the property chain.
{
var currentNode = new PropertyObserverNode(propName, _action);
previousNode.Next = currentNode;
previousNode = currentNode;
}
object? propOwnerObject = constantExpression.Value;
if (propOwnerObject is not INotifyPropertyChanged inpcObject)
throw new InvalidOperationException("Tried to subscribe to PropertyChanged in the object that " +
$"defines the '{propObserverNodeRoot.PropertyInfo.Name}' property, but the object does not implement INotifyPropertyChanged.");
propObserverNodeRoot.SubscribeListenerFor(inpcObject);View on GitHub (pinned to 358118cd64)