reactiveui / ReactiveUI

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
https://www.reactiveui.net
MIT License
8.05k stars 1.12k forks source link

[BUG] RoutedViewHost, IPlatformOperations, Uno, WASM #2528

Closed ushenkodmitry closed 3 years ago

ushenkodmitry commented 4 years ago

Describe the bug Default splashscreen with exception in browser's console

LogHost: You will need to install the specific host package for your platform (ReactiveUI.WPF, ReactiveUI.Blazor, ...)
dotnet.js:1 
dotnet.js:1 LogHost: You can install the needed package via NuGet, see https://reactiveui.net/docs/getting-started/installation/
dotnet.js:1 RoutedViewHost: Couldn't find an IPlatformOperations implementation. Please make sure you have installed the latest version of the ReactiveUI packages for your platform. See https://reactiveui.net/docs/getting-started/installation for guidance.
dotnet.js:1 fail: Windows.UI.Core.CoreDispatcher[0]
dotnet.js:1       Dispatcher unhandled exception
dotnet.js:1 System.Exception: Failed to load App1.Views.RootPage: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Don't know how to detect when ReactiveUI.Uno.RoutedViewHost is activated/deactivated, you may need to implement IActivationForViewFetcher
dotnet.js:1   at ReactiveUI.ViewForMixins.WhenActivated (ReactiveUI.IActivatableView item, System.Func`1[TResult] block, ReactiveUI.IViewFor view) [0x00021] in D:\a\1\s\src\ReactiveUI\Activation\ViewForMixins.cs:156 
dotnet.js:1   at ReactiveUI.ViewForMixins.WhenActivated (ReactiveUI.IActivatableView item, System.Action`1[T] block, ReactiveUI.IViewFor view) [0x0000d] in D:\a\1\s\src\ReactiveUI\Activation\ViewForMixins.cs:207 
dotnet.js:1   at ReactiveUI.ViewForMixins.WhenActivated (ReactiveUI.IActivatableView item, System.Action`1[T] block) [0x00000] in D:\a\1\s\src\ReactiveUI\Activation\ViewForMixins.cs:185 
dotnet.js:1   at ReactiveUI.Uno.RoutedViewHost..ctor () [0x001c3] in D:\a\1\s\src\ReactiveUI\Platforms\windows-common\RoutedViewHost.cs:106 

Steps To Reproduce

Expected behavior

Application's first view shown.

Screenshots

Environment

Additional context It seems adding RoutedViewHost breaks everything. Application was running fine until RoutedViewHost was added with XAML below:

<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:rxui="using:ReactiveUI"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <TextBlock Text="Hello, world!" Margin="20" FontSize="30" />
        <rxui:RoutedViewHost HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Margin="8" />
    </Grid>
</Page>
ushenkodmitry commented 3 years ago

Hello there, with the latest ReactiveUI.Uno i'm getting exception System.Exception: Failed to load App1.MainPage: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Don't know how to detect when ReactiveLinker.MainPage is activated/deactivated, you may need to implement IActivationForViewFetcher when i'm adding

    this.WhenActivated(d => { });

in the main page ctor. Only in WASM.

ushenkodmitry commented 3 years ago

Hello, any suggestion where to look?

ushenkodmitry commented 3 years ago

Hello again, Great job! It seems it is now working with the latest ReactiveUI.Uno and Uno.

    <PackageReference Include="ReactiveUI.Fody" Version="13.0.27" />
    <PackageReference Include="ReactiveUI.Uno" Version="13.0.27" />
    <PackageReference Include="Splat.Autofac" Version="9.8.1" />
    <PackageReference Include="Splat.Microsoft.Extensions.DependencyInjection" Version="9.8.1" />
    <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI.Controls" Version="6.1.0-build.205.g2e0e348372" />
    <PackageReference Include="Uno.UI.WebAssembly" Version="3.4.0-dev.356" />
    <PackageReference Include="Uno.Wasm.Bootstrap" Version="2.0.0-dev.125" />
    <PackageReference Include="Uno.Wasm.Bootstrap.DevServer" Version="2.0.0-dev.125" />
ushenkodmitry commented 3 years ago

Nope, not working.

glennawatson commented 3 years ago

How you using autofac? It's the likely issue

glennawatson commented 3 years ago

Well the fact you've got two competing di installations

ushenkodmitry commented 3 years ago

Finally, i figured it out. ActivationForViewFetcher implementation was not registered in the container. Adding ActivationForViewFetcher implementation from ReactiveUI.Uno package did the trick. It seems that InitializeReactiveUI() doesn't register the implementation when running on WASM. That's another story. So i'm closing this. And yes, you were right. I had both MSDI and Autofac in my dependencies. Now i'm on MSDI, as Autofac, as you said, has some issues.

github-actions[bot] commented 2 years ago

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.