Emil Nyborg
Emil Nyborg

Reputation: 73

WPF Caliburn.Micro uses wrong platform provider

In my ShellViewModel PlatformProvider.Current results in a XamlPlatformProvider as expected. In another ViewModel navigated to in a Frame PlatformProvider.Current results in a DefaultPlatformProvider. Furthermore if I trigger a function in the ShellViewModel I can see that PlatformProvider.Current still results in a XamlPlatformProvider, so that ViewModel isn't affected.

This results in errors on Caliburn.Micro.Execute.OnUIThread and other platform specific calls such as using a BindableCollection. It started happening after updating a large project to Caliburn.Micro version 4.0.173 from version 3.2.0.

I've been unable to reproduce the error in a smaller test project, so I can not show meaningful code. I've tried replacing the whole bootstrapper with a minimal one and still see the error.

EDIT: Creating a UI component from code within Caliburn.Micro.Execute.BeginOnUIThread gives the error: "The calling thread must be STA, because many UI components require this". Altering a BindableCollection gives the error: "This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread."

The above scenarios work if I wrap them in a Application.Current.Dispatcher.Invoke which indicates that Caliburn.Micro fails to use the Dispatcher/UI thread.

I'm using C# on .NET Framework 4.8.

Upvotes: 0

Views: 256

Answers (1)

Emil Nyborg
Emil Nyborg

Reputation: 73

The second ViewModel, which was throwing errors was in a second project that included the NuGet package Caliburn.Micro.Core instead of Caliburn.Micro. Updating both to the same version solved the issue. I had used NuGets Consolidate function to update Caliburn.Micro in the whole solution and had missed Caliburn.Micro.Core.

Upvotes: 1

Related Questions