PrismLibrary/Prism · error · InvalidOperationException

Tried to subscribe to PropertyChanged in the object that…

Error message

Tried to subscribe to PropertyChanged in the object that defines the '{Next?.PropertyInfo.Name}' property, but the object does not implement INotifyPropertyChanged.

What it means

When a middle node in the property chain resolves its property value to advance the chain, that intermediate value must implement INotifyPropertyChanged for the observer to keep listening. If the intermediate object is a plain object, this InvalidOperationException is thrown.

Solutions

  1. Make the intermediate child class implement INotifyPropertyChanged
  2. Derive the intermediate class from BindableBase/ObservableObject
  3. Restructure the observed chain to stop at observable objects

Example fix

// before
class Child { public string Name { get; set; } }
// after
class Child : BindableBase { private string _name; public string Name { get => _name; set => SetProperty(ref _name, value); } }
Defensive patterns

Strategy: validation

Validate before calling

var mid = vm.PlainChild;
bool ok = mid == null || mid is INotifyPropertyChanged;
// only build chains whose intermediate objects are observable

Type guard

static bool ChainIsObservable(object root, params string[] path) { /* walk path checking each value is null or INotifyPropertyChanged */ return true; }

Try / catch

try { PropertyObserver.Create(() => vm.Child.Sub).Subscribe(); }
catch (InvalidOperationException) { /* intermediate child lacks INPC */ }

Prevention

When it happens

Trigger: Observing a chain like () => vm.PlainChild.SubProperty where vm.PlainChild returns an object that does not implement INotifyPropertyChanged and is not null.

Common situations: Nested view-models where an inner child class was forgotten to be made observable; refactors that replaced an observable child with a POCO.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at src/Prism.Core/Commands/PropertyObserverNode.cs:45

                Next.UnsubscribeListener();
                GenerateNextNode();
            };
        }

        public void SubscribeListenerFor(INotifyPropertyChanged inpcObject)
        {
            _inpcObject = inpcObject;
            _inpcObject.PropertyChanged += OnPropertyChanged;

            if (Next != null) GenerateNextNode();
        }

        private void GenerateNextNode()
        {
            var nextProperty = PropertyInfo.GetValue(_inpcObject);
            if (nextProperty == null) return;
            if (nextProperty is not INotifyPropertyChanged nextInpcObject)
                throw new InvalidOperationException("Tried to subscribe to PropertyChanged in the object that " +
                                                    $"defines the '{Next?.PropertyInfo.Name}' property, but the object does not implement INotifyPropertyChanged.");

            Next?.SubscribeListenerFor(nextInpcObject);
        }

        private void UnsubscribeListener()
        {
            if (_inpcObject != null)
                _inpcObject.PropertyChanged -= OnPropertyChanged;

            Next?.UnsubscribeListener();
        }

        private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
        {
            if (e?.PropertyName == PropertyInfo.Name || string.IsNullOrEmpty(e?.PropertyName))
            {
                _action?.Invoke();

View on GitHub (pinned to 358118cd64)