我最近将我的项目升级到RxUI 7.0(从6.5开始)。启动我的UWP应用程序时,它会立即崩溃并出现以下异常:
System.TypeInitializationException: The type initializer for 'ReactiveUI.RxApp' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: dispatcher
这是一个堆栈跟踪:
at System.Reactive.Concurrency.CoreDispatcherScheduler..ctor(CoreDispatcher dispatcher)
at System.Reactive.Concurrency.CoreDispatcherScheduler.get_Current()
at ReactiveUI.PlatformRegistrations.<>c.<Register>b__0_5()
at ReactiveUI.WaitForDispatcherScheduler.attemptToCreateScheduler()
at ReactiveUI.PlatformRegistrations.Register(Action`2 registerFunction)
at ReactiveUI.DependencyResolverMixins.InitializeReactiveUI(IMutableDependencyResolver resolver)
at ReactiveUI.RxApp.<>c.<.cctor>b__0_0()
at Splat.Locator.RegisterResolverCallbackChanged(Action callback)
at ReactiveUI.RxApp..cctor()
这是另一个
at ReactiveUI.RxApp.get_MainThreadScheduler()
at ReactiveUI.ReactiveList`1.setupRx(IEnumerable`1 initialContents, Double resetChangeThreshold, IScheduler scheduler)
at ReactiveUI.ReactiveList`1..ctor()
at NewBooru.ViewModels.HamburgerViewModel..ctor()
at NewBooru.Views.MainPage..ctor()
at NewBooru.NewBooru_XamlTypeInfo.XamlTypeInfoProvider.Activate_31_MainPage()
at NewBooru.NewBooru_XamlTypeInfo.XamlUserType.ActivateInstance()
崩溃的代码:
public HamburgerViewModel()
{
MenuItems = new ReactiveList<MenuItem>
{
new MenuItem("link", "name", enum)
};
}
我无法想象这会因单元测试或任何手动测试而滑落。我是否需要在新版本中进行额外的初始化?
答案 0 :(得分:1)
事实证明,问题是应用程序的核心Dispatcher在App的OnLaunched之前没有初始化。 ReactiveUI期望Dispatcher处于活动状态,如果不存在则会失败。 Here's a link在ReactiveUI repo中跟踪此问题。
解决方案是等待从ReactiveUI调用任何内容,直到应用程序触发OnLaunched为止。