问题
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