Skip to content

WhenPropertyChanged: subscribe when the target implements INotifyPropertyChanged at runtime - #1235

Open
menes97 wants to merge 1 commit into
reactivemarbles:mainfrom
menes97:fix/when-property-changed-runtime-inpc
Open

menes97 wants to merge 1 commit into
reactivemarbles:mainfrom
menes97:fix/when-property-changed-runtime-inpc

Conversation

@menes97

@menes97 menes97 commented Nov 18, 2026

Copy link
Copy Markdown

Fixes #1156.

ExpressionBuilder.CreatePropertyChangedFactory decided when the expression was built whether to subscribe: it only did so if the property's declaring type implements INotifyPropertyChanged. For a property declared on a plain interface (IHasPlainAge.Age), WhenValueChanged/WhenPropertyChanged therefore never subscribed, even when the object at runtime implements INotifyPropertyChanged, which is the scenario described in the issue.

The factory now returns Never only when the expression isn't a property access; otherwise it checks target is INotifyPropertyChanged per instance and subscribes through that.

Behaviour change: subscriptions now happen for objects that implement INotifyPropertyChanged at runtime even when the declared type in the expression doesn't. Every case that subscribed before still does (an instance of an INPC-declaring type is itself INPC); objects that don't implement INPC still get Never.

Test. PropertyIsDeclaredOnInterfaceWithoutNotification_ChangesAreStillObserved in WhenPropertyChangedFixture.UnitTests, next to ExpressionContainsImplicitInterfaceCast, with supporting types IHasPlainAge and NotifyingChildModel. It fails without the change (no value change recorded) and passes with it.

Ran (net9.0): the WhenPropertyChangedFixture tests fail 1/43 before and pass after; the Binding/WhenPropertyChanged/WhenValueChanged/AutoRefresh tests pass (278). A full DynamicData.Tests run on net9.0 passed 2631 / 0 failed / 17 skipped. Only net9.0 was built and tested.

This change was written with Claude Code.

🤖 Generated with Claude Code

…rtyChanged only at runtime

The property-changed factory decided at expression-build time whether to
subscribe, based on whether the property's declaring type implements
INotifyPropertyChanged. When the property is declared on a plain interface
(or base type) and the target object implements INotifyPropertyChanged, no
subscription was made and later changes were never observed. Check the
target instance instead.

Fixes reactivemarbles#1156

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WhenPropertyChanged() does not recognize INotifyPropertyChanged when casting is involved.

1 participant