【问题标题】:Minimum runnable example for ReactiveUI - not runningReactiveUI 的最小可运行示例 - 未运行
【发布时间】:2020-03-06 21:33:00
【问题描述】:

我想为我的 ReactiveUI 问题生成一个 MWE。但是我遇到了新的问题。

这是我尝试过的:

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();
        }
    }
}

我得到的运行时错误是:

TypeLoadException: Typ 的方法“GetActivationForView” "ReactiveUI.ActivationForViewFetcher" der 程序集 "ReactiveUI.WPF, Version=9.11.0.0,Culture=neutral,PublicKeyToken=null" 没有 实施。

【问题讨论】:

  • 我在新的 Fullframework 4.7.2 WPF 应用程序中尝试了您的代码,参考 ReactiveUi v 11.1.1 并将您的代码粘贴到 MainWindow.xaml.cs 中。输出符合预期,没有错误。您正在使用什么类型的项目?也许升级?
  • @OzBob:感谢您的测试。找到问题的根本原因(缺少 nuget-package)。

标签: c# reactiveui


【解决方案1】:

找到解决方案:

Nuget 数据包:未安装 ReactiveUI.WPF。

现在作为纯控制台应用程序工作。

输出:

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

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-27
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    相关资源
    最近更新 更多