Minimum runnable example for ReactiveUI - not running

你离开我真会死。 提交于 2020-03-25 19:45:32

问题


I wanted to generate a MWE for my ReactiveUI problem. However I came across new problems.

This is what i tried:

using System;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

namespace ReactivUI_Test
{
    class BarClass : ReactiveObject
    {
        [Reactive] public String Baz { get; set; } = "";
        public BarClass(String b) { Baz = b; }
        public BarClass() { Baz = "!!!"; }
        public override String ToString() { return Baz.ToString(); }
    }



    class FooClass : ReactiveObject
    {
        [Reactive] public BarClass Bar { get; set; } = new BarClass();
        public override String ToString() { return Bar.ToString(); }
    }


    class ViewModel: ReactiveObject
    {
        [Reactive] FooClass Foo { get; set; } = new FooClass();

        public ViewModel()
        {
            this.WhenAnyValue(x => x.Foo.Bar.Baz)
                 .Subscribe(x => Console.WriteLine("Hallo " + x?.ToString()));          // <- Runtime Error in this line

            Console.WriteLine("Example 1");
            this.Foo.Bar.Baz = null;
            Console.WriteLine("Example 2a");
            this.Foo.Bar = new BarClass();
            Console.WriteLine("Example 2b");
            this.Foo.Bar = new BarClass();
            Console.WriteLine("Example 3");
            this.Foo.Bar = new BarClass() { Baz = "Something" };

            Console.WriteLine("Example 4");
            this.Foo = new FooClass() ;

            Console.WriteLine("Finish");
            Console.ReadLine();
        }
    }


    class Program 
    {
        static void Main(string[] args)
        {
            ViewModel vm = new ViewModel();
        }
    }
}

The runtime error I get is:

TypeLoadException: The method "GetActivationForView" of Typ "ReactiveUI.ActivationForViewFetcher" der Assembly "ReactiveUI.WPF, Version=9.11.0.0, Culture=neutral, PublicKeyToken=null" has no Implementation.


回答1:


Solution found:

Nuget packet: ReactiveUI.WPF was not installed.

Now working as pure console application.

Output:

Hallo !!!
Example 1
Hallo
Example 2a
Hallo !!!
Example 2b
Example 3
Hallo Something
Example 4
Hallo !!!


来源:https://stackoverflow.com/questions/59511372/minimum-runnable-example-for-reactiveui-not-running

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!