Skip to content

[Bug]: WinUI/WAS - ReactiveUI.WinUi nuget attempts to load the ReactiveUI.XamForms assembly when WhenActivated is called on a IActivatableViewModel #3786

Closed
@matthewacme

Description

@matthewacme

Describe the bug 🐞

In a WinUI 3 app project that has a dependency on the ReactiveUI.WinUI nuget package, if you add the IActivatableViewModel interface to a view model and implement the interface, then in the Constructor for that view model set up the WhenActivated Linq method in the constructor. When the Constructor is loaded, ReactiveUI raises an error of
"Could not load file or assembly 'ReactiveUI.XamForms, Version=19.6.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified."

This is a bug, the XamForms assembly can not be referenced in a WinUI project, nor should it be needed

Step to reproduce

  1. start a new WinUI 3 App - Blank project
    image

  2. Add A Class and cal it MainPageViewModel

  3. on the main page add a Dependency property to the newly created MainPageViewModel

  4. In the MainPage constructor, initialize the dependency property to a new instance of MainPageViewModel

  5. Add ReactiveUI.WinUI nuget dependency to the project

  6. Run the project, it runs fine

  7. Stop Project.

  8. Add the IActivatableViewModel interface to MainPageViewModel and implement it.

  9. Modify the constructor for the MainPageViewModel to be like so

    public MainPageViewModel()
    {
        Activator = new ViewModelActivator();

        ( this ).WhenActivated(disposables =>
        {
            // Use WhenActivated to execute logic
            // when the view model gets activated.
           // do nothing, this is just to cause the bug
            // HandleActivation(disposables);
        });
    }
  1. Run it, and you will break on the line
    ( this ).WhenActivated(disposables =>

with the error of

System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'ReactiveUI.XamForms, Version=19.6.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Source=
StackTrace:

If you put a breakpoint i

Reproduction repository

https://github.com/xsgeek/ReactiveUI-WinUI-Bug

Expected behavior

The WinUI project should run just fine with just a reference to the ReactiveUI.WinUI assembly.

Screenshots 🖼️

No response

IDE

Visual Studio 2022

Operating system

Windows 11

Version

net7.0-windows10.0.22621.0

Device

Windows

ReactiveUI Version

19.6.1

Additional information ℹ️

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions