uno: System.InvalidCastException: Unable to cast object of type ' XXXX' to type 'YYYY'

Current behavior

Hello, our project uses the c# language to develop the Uno framework + Gtk + Skia running on the Linux platform project, and it is always triggered occasionally when InitializeComponent() is executed

System.InvalidCastException: Unable to cast object of type 'XXXXX' to type 'YYYYY'.””The following is an error message for one of them." ---> System.InvalidCastException: Unable to cast object of type 'System.Double' to type 'Windows.UI.Xaml.Input.XYFocusKeyboardNavigationMode'.
   at Windows.UI.Xaml.UIElement.OnXYFocusKeyboardNavigationBackingFieldUpdate(Object instance, Object newValue)
   at Windows.UI.Xaml.DependencyObjectStore.InvokeCallbacks(DependencyObject actualInstanceAlias, DependencyProperty property, DependencyPropertyDetails propertyDetails, Object previousValue, DependencyPropertyValuePrecedences previousPrecedence, Object newValue, DependencyPropertyValuePrecedences newPrecedence, Boolean bypassesPropagation)
   at Windows.UI.Xaml.DependencyObjectStore.RaiseCallbacks(DependencyObject actualInstanceAlias, DependencyPropertyDetails propertyDetails, Object previousValue, DependencyPropertyValuePrecedences previousPrecedence, Object newValue, DependencyPropertyValuePrecedences newPrecedence)
   at Windows.UI.Xaml.DependencyObjectStore.InnerSetValue(DependencyProperty property, Object value, DependencyPropertyValuePrecedences precedence, DependencyPropertyDetails propertyDetails, Boolean isPersistentResourceBinding)
   at Windows.UI.Xaml.DependencyObjectStore.OnParentPropertyChangedCallback(ManagedWeakReference sourceInstance, DependencyProperty parentProperty, Object newValue)
   at Windows.UI.Xaml.DependencyObjectStore.OnParentPropertyChangedCallback(ManagedWeakReference sourceInstance, DependencyProperty parentProperty, Object newValue)
   at Windows.UI.Xaml.DependencyObjectStore.<PropagateInheritedProperties>g__Propagate|151_0(DependencyObjectStore store, <>c__DisplayClass151_0&)
   at Windows.UI.Xaml.DependencyObjectStore.PropagateInheritedProperties(DependencyObjectStore childStore)
   at Windows.UI.Xaml.DependencyObjectStore.RegisterInheritedPropertyChangedCallback(DependencyObjectStore childStore)
   at Windows.UI.Xaml.DependencyObjectStore.RegisterInheritedProperties(IDependencyObjectStoreProvider parentProvider)
   at Windows.UI.Xaml.DependencyObjectStore.TryRegisterInheritedProperties(IDependencyObjectStoreProvider parentProvider, Boolean force)
   at Windows.UI.Xaml.DependencyObjectStore.set_Parent(Object value)
   at Windows.UI.Xaml.DependencyObjectExtensions.SetParent(IDependencyObjectStoreProvider storeProvider, Object parent)
   at Windows.UI.Xaml.UIElement.AddChild(UIElement child, Nullable`1 index)
   at Windows.UI.Xaml.Controls.Control.RegisterSubView(UIElement child)
   at Windows.UI.Xaml.Controls.Control.set_TemplatedRoot(UIElement value)
   at Windows.UI.Xaml.Controls.Control.UpdateTemplate()
   at Windows.UI.Xaml.Controls.Control.SetUpdateControlTemplate(Boolean forceUpdate)
   at Windows.UI.Xaml.Controls.Control.OnTemplateChanged(DependencyPropertyChangedEventArgs e)
   at Windows.UI.Xaml.Controls.Control.<>c.<.cctor>b__379_0(DependencyObject s, DependencyPropertyChangedEventArgs e)
   at Windows.UI.Xaml.DependencyObjectStore.InvokeCallbacks(DependencyObject actualInstanceAlias, DependencyProperty property, DependencyPropertyDetails propertyDetails, Object previousValue, DependencyPropertyValuePrecedences previousPrecedence, Object newValue, DependencyPropertyValuePrecedences newPrecedence, Boolean bypassesPropagation)
   at Windows.UI.Xaml.DependencyObjectStore.RaiseCallbacks(DependencyObject actualInstanceAlias, DependencyPropertyDetails propertyDetails, Object previousValue, DependencyPropertyValuePrecedences previousPrecedence, Object newValue, DependencyPropertyValuePrecedences newPrecedence)
   at Windows.UI.Xaml.DependencyObjectStore.InnerSetValue(DependencyProperty property, Object value, DependencyPropertyValuePrecedences precedence, DependencyPropertyDetails propertyDetails, Boolean isPersistentResourceBinding)
   at Windows.UI.Xaml.Setter.ApplyTo(DependencyObject o)
   at Windows.UI.Xaml.Style.ApplyTo(DependencyObject o, DependencyPropertyValuePrecedences precedence)
   at Windows.UI.Xaml.FrameworkElement.OnStyleChanged(Style oldStyle, Style newStyle, DependencyPropertyValuePrecedences precedence)
   at Windows.UI.Xaml.FrameworkElement.ApplyStyle()
   at Windows.UI.Xaml.FrameworkElement.ApplyStyles()
   at Windows.UI.Xaml.FrameworkElement.CreationComplete()
   at Uno.IntegrationTestPlatform.MyWindow.<>c.<InitializeComponent_44A45F2C>b__99_28(Button c18) in H:\Workflow\Vinno.Uno\Uno.IntegrationTestPlatform\obj\Release\netstandard2.0\g\XamlCodeGenerator\MyWindow_4a111db79bb1ee9bef1f3d2bdd7edb6c.g.cs:line 471"

Expected behavior

No response

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

None

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

<PackageReference Include="Uno.UI" Version="4.9.17" />",

Affected platforms

Skia (GTK on Linux/macOS/Windows)

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (17 by maintainers)

Most upvoted comments

@jeromelaban I think some of the recent changes (specifically related to performance) assumed that certain code paths are only run in the UI thread.

Could it be something running in a different thread causing a race? In the stacktrace in the original post here, there is IntegrationTestPlatform in the stack trace. That would also explain why there is no 100% reliable repro.