c# - ReactiveUI - 当 ToProperty 在同一个 Observable 上正常时 ReactiveCommand 失败
问题描述
我有一个 ReactiveCommand 引发以下错误。
实现 IHandleObservableErrors 的对象(通常是 ReactiveCommand 或 ObservableAsPropertyHelper)发生错误,从而破坏了其可观察管道。为防止这种情况,请确保管道不会出错,或订阅相关对象的 ThrownExceptions 属性以处理错误情况。
这是代码(方法A):
private List<Dto> _items;
public List<Dto> Items
{
get => _items;
set => this.RaiseAndSetIfChanged(ref _items, value);
}
RefreshCommand = ReactiveCommand.CreateFromObservable(() => GetItems
.Do(dtos => Items = dtos)
.Select(_ => Unit.Default))
.DisposeWith(Disposables);
RefreshCommand.ThrownExceptions.Subscribe(err => Console.WriteLine(err.ToString()));
RefreshCommand.ExecuteIfPossible();
我还尝试了其他方法(方法 B):
private readonly ObservableAsPropertyHelper<List<Dto>> _items;
public List<Dto> Items => _items.Value;
this._items = GetItems.ToProperty(this, x => x.Items);
我的问题是:
- 如果我订阅了 `ThrownExceptions`,为什么方法 A 会抛出错误?请注意,永远不会命中 `Console.WriteLine(err.ToString())`。
- 为什么方法 B 在知道方法 A 失败的情况下工作正常?
我正在使用Uno.ReactiveUI,它是 reactiveUI 8.0.0 版的一个分支
谢谢你。
更新
如果我注释掉ExecuteIfPossible
并点击RefreshCommand
绑定的按钮,那么我没有运行时错误。当我离开ExecuteIfPossible
时,内在的例外是
无法加载文件或程序集“Uno.Foundation,版本=255.255.255.255,文化=中性,PublicKeyToken=null”。该系统找不到指定的文件。
我什至不知道什么ExecuteIfPossible
是诚实的。我只是想打电话Execute(null)
,但智能感知不会让我(也不会编译)。所以这肯定与 ReactiveUI 的 Uno 实现有关。
更新2
为了Execute
可用,我必须使用RefreshCommand
type ReactiveCommand<Unit, Unit>
。然后我可以编写以下内容,一切都按预期工作。
RefreshCommand.Execute(Unit.Default).Subscribe().DisposeWith(Disposables);
更新3
这个问题毫无意义,应该“关闭”,因为该问题与其标题或描述无关。只有我:
- 没有正确使用 ReactiveUI
- 调用一个抛出异常的 Uno.Client 方法并且错误地断定这是一个 ReactiveUI 问题,而实际上它不是。
感谢那些花时间帮助我的人。
解决方案
推荐阅读
- linux - 仅列出文件;iconv 和目录?
- javascript - 使用 Angular5 和 AngularJS 的聚合物
- java - 迭代嵌入式链接时出现 StaleElementReferenceException
- maven - 与源文件夹相比,Eclipse 以不同颜色显示源文件夹之一(src/test) - src/main?
- installation - 当我调用 apt-get install llvm 时会发生什么?
- c# - 如何知道组合框是否绑定?
- ios - Swift 类未从情节提要中正确加载
- javascript - 任何允许在网站上发布收到的 WhatsApp 消息的 API 或其他东西
- angular - Angular 5 上的单元测试 http 服务
- c# - C# 使用 CSV 标头为不同的变量赋值