Skip to content

Fix broken view model activation from ambiguous ViewModel property - #163

Merged
glennawatson merged 2 commits into
mainfrom
copilot/fix-broken-view-model-activation
Aug 3, 2026
Merged

glennawatson merged 2 commits into
mainfrom
copilot/fix-broken-view-model-activation

Conversation

Copilot AI commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

ReactiveWindowBase/ReactiveUserControlBase and their generic subclasses each declared a public ViewModel property of differing return types (object? vs TViewModel?). Since both are public, Type.GetProperty("ViewModel") throws AmbiguousMatchException, which ReactiveUI hits during activation (view.WhenAnyValue<IViewFor, object>("ViewModel")) — silently breaking view model activation when no explicit viewModelChanged is supplied.

Changes

  • Base classes expose ViewModel explicitly — ReactiveWindowBase/ReactiveUserControlBase implement object? IViewFor.ViewModel (explicit interface member, not CLR-public), so it no longer collides with the generic subclass's property.
  • Generic classes keep a single public typed property — ReactiveWindow<T>/ReactiveUserControl<T> drop the new shadowing and back ViewModel directly with GetValue/SetValue(ViewModelProperty). A concrete ReactiveWindow<VM> now exposes exactly one public ViewModel, so reflection resolves cleanly.
  • Registration name updated — ViewModelProperty uses nameof(IViewFor.ViewModel) since ViewModel is no longer a base class-level member. The Avalonia property itself is unchanged, so the notification factory still resolves via the property registry.
  • Tests — added regression coverage (single resolvable typed property + end-to-end activation) and updated existing tests that touched the base ViewModel to go through ((IViewFor)x).ViewModel.
// Base: explicit, non-public
object? IViewFor.ViewModel
{
    get => GetValue(ViewModelProperty);
    set => SetValue(ViewModelProperty, value);
}

// Generic: the only public ViewModel
public TViewModel? ViewModel
{
    get => (TViewModel?)GetValue(ViewModelProperty);
    set => SetValue(ViewModelProperty, value);
}

Copilot AI linked an issue Aug 3, 2026 that may be closed by this pull request
@codecov

codecov Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.89%. Comparing base (30635fd) to head (60aae68).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #163   +/-   ##
=======================================
  Coverage   87.89%   87.89%           
=======================================
  Files          18       18           
  Lines         636      636           
  Branches      105      105           
=======================================
  Hits          559      559           
  Misses         76       76           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI changed the title [WIP] Fix broken view model activation due to ambiguous match exception Fix broken view model activation from ambiguous ViewModel property Aug 3, 2026
Copilot AI requested a review from ChrisPulman August 3, 2026 00:50
@ChrisPulman
ChrisPulman marked this pull request as ready for review August 3, 2026 07:06
@glennawatson
glennawatson merged commit 0b7b2ca into main Aug 3, 2026
6 checks passed
@glennawatson
glennawatson deleted the copilot/fix-broken-view-model-activation branch August 3, 2026 08:06
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Broken view model activation.

3 participants