Skip to content

[Bug]: IActivationForViewFetcher seems to be not available when using example code from readme #39

@dabbinavo

Description

@dabbinavo

Describe the bug 🐞

I am not sure if this is an bug or desired behaviour. It took me several hours to find a solution for the issue, so it might be useful if the documentation is clarified in case this is not a bug.

Using the proposed setup method from the README

public static AppBuilder BuildAvaloniaApp() => AppBuilder
    .Configure<App>()
    .UsePlatformDetect()
    .UseReactiveUIWithMicrosoftDependencyResolver(
        services =>
        {
            // services.AddSingleton<MainViewModel>();
        },
        withResolver: sp =>
        {
            // Optional: access ServiceProvider
        },
        withReactiveUIBuilder: rxui =>
        {
            // Optional ReactiveUI customizations
        })
    .RegisterReactiveUIViewsFromEntryAssembly();

leaded to the following runtime exception in my case:

An exception of type 'System.ArgumentException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'Don't know how to detect when Views.MainView is activated/deactivated, you may need to implement IActivationForViewFetcher'
   at ReactiveUI.ViewForMixins.WhenActivated(IActivatableView item, Func`1 block, IViewFor view)
   at ReactiveUI.ViewForMixins.WhenActivated(IActivatableView item, Action`1 block, IViewFor view)
   at ReactiveUI.ViewForMixins.WhenActivated(IActivatableView item, Action`1 block)
   at ReactiveUI.Avalonia.ReactiveUserControl`1..ctor()
   at Views.MainView..ctor() in ...

When calling the other method without the withReactiveUIBuilder argument instead, everything works as expected:

public static AppBuilder BuildAvaloniaApp() => AppBuilder
    .Configure<App>()
    .UsePlatformDetect()
    .UseReactiveUIWithMicrosoftDependencyResolver(
        services =>
        {
            // services.AddSingleton<MainViewModel>();
        },
        withResolver: sp =>
        {
            // Optional: access ServiceProvider
        })
    .RegisterReactiveUIViewsFromEntryAssembly();

Step to reproduce

See description.

Reproduction repository

No response

Expected behavior

It should be more clear when to use which function.

Screenshots 🖼️

No response

IDE

Visual Studio Code

Operating system

Windows 11

Version

No response

Device

No response

ReactiveUI.Avalonia Version

11.3.8

Additional information ℹ️

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions