Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
matthewacme opened this issue Apr 15, 2024 · 6 comments
Labels

Comments

@matthewacme
Copy link

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

@anaisbetts
Copy link
Member

Are you breaking in on first-chance exceptions? This is expected but this exception should be handled

@matthewacme
Copy link
Author

matthewacme commented Apr 16, 2024 via email

@dpvreony
Copy link
Member

see if the following workaround prevents the issue. you need one of these in app initialisation before ReactiveUI is called.

if you're not doing any custom Splat DI config.

ReactiveUI.PlatformRegistrationManager.SetRegistrationNamespaces(RegistrationNamespace.WinUI);

if you're doing any custom config to Splat etc. you'll need something along the lines of. (you might want this version anyway so it's clearer when ReactiveUI is being set up)

Locator.CurrentMutable.InitializeSplat();
Locator.CurrentMutable.InitializeReactiveUI(RegistrationNamespace.WinUI); 

If the Assembly scanning is the issue, this should prevent it.

@matthewacme
Copy link
Author

matthewacme commented Apr 16, 2024 via email

@matthewacme
Copy link
Author

@dpvreony

Thank you, that worked perfectly...

hopefully anyone else coming across this bug will find this answer.

Copy link

github-actions bot commented May 2, 2024

This issue 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 May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants