XAMLMarkupExtensions/WPFLocalizeExtension

KeyNotFoundException causing crash after updating to WPFLocalizeExtension 3.9.0

Genteure opened this issue · 2 comments

Describe the bug

After updating WPFLocalizeExtension from 3.8.0 to 3.9.0, crashes started to happen due to System.Collections.Generic.KeyNotFoundException.

To Reproduce
I don't have a way to reproduce.
Currently about 0.54% of the users (~20 out of ~3700) crashed at least once based on crash telemetry from sentry.io.

Expected behavior
Not crash.

Screenshots
A user provided screen recording of the crash happening.

WPFLocalizeExtension-crash.mp4

My observations:

  • Only one instance out of the two running crashed
  • Strings didn't load correctly, showing as Key: KeyName
    • This also happend on WPFLocalizeExtension 3.8.0 based on user feedback, but it's pretty rare and didn't crash so I just ignored it.
  • It seems like the crash happend when the user moved his cursor on a UI element that has a popup. Stacktrace also confirms it indeed involves Popup.
  • The crash may be related to remote desktop / desktop environment changing, but I'm not sure.

Enviroment (please complete the following information):

  • OS: Windows 10, Windows 7
  • .NET Framework: .NET Framework 4.8, .NET Framework 4.7.2

Additional context

Full stacktrace from sentry.io
System.Collections.Generic.KeyNotFoundException: 给定关键字不在字典中。
  ?, in TValue Dictionary<TKey, TValue>.get_Item(TKey key)
  File "D:\a\XAMLMarkupExtensions\XAMLMarkupExtensions\src\Base\TargetObjectsList.cs", line 82, col 13, in void TargetObjectsList.AddTargetObjectProperty(WeakReference targetObjectWeakReference, object targetProperty, Type targetPropertyType, int targetPropertyIndex)
  File "D:\a\XAMLMarkupExtensions\XAMLMarkupExtensions\src\Base\NestedMarkupExtension.cs", line 286, col 13, in object NestedMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
  ?, in object StyleHelper.GetInstanceValue(UncommonField<HybridDictionary[]> dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, int childIndex, DependencyProperty dp, int i, ref EffectiveValueEntry entry)
  ?, in object StyleHelper.GetChildValueHelper(UncommonField<HybridDictionary[]> dataField, ref ItemStructList<ChildValueLookup> valueLookupList, DependencyProperty dp, DependencyObject container, FrameworkObject child, int childIndex, bool styleLookup, ref Eff...
  ?, in object StyleHelper.GetChildValue(UncommonField<HybridDictionary[]> dataField, DependencyObject container, int childIndex, FrameworkObject child, DependencyProperty dp, ref FrugalStructList<ChildRecord> childRecordFromChildIndex, ref EffectiveValueEntry ...
  ?, in bool StyleHelper.GetValueFromTemplatedParent(DependencyObject container, int childIndex, FrameworkObject child, DependencyProperty dp, ref FrugalStructList<ChildRecord> childRecordFromChildIndex, FrameworkElementFactory templateRoot, ref EffectiveValueEntry entry)
  ?, in void StyleHelper.ApplyTemplatedParentValue(DependencyObject container, FrameworkObject child, int childIndex, ref FrugalStructList<ChildRecord> childRecordFromChildIndex, DependencyProperty dp, FrameworkElementFactory templateRoot)
  ?, in void StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, int childIndex, ref FrugalStructList<ChildRecord> childRecordFromChildIndex, bool isDetach, FrameworkElementFactory templateRoot)
  ?, in void FrameworkTemplate.InvalidatePropertiesOnTemplate(DependencyObject container, object currentObject)
  ?, in void FrameworkTemplate.HandleBeforeProperties(object createdObject, ref DependencyObject rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
  ?, in DependencyObject FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List<DependencyObject> affectedChildren, UncommonField<Hashtable> templatedNonFeChildrenF...
  ?, in void XamlObjectWriter.OnBeforeProperties(object value)
  ?, in void XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
  ?, in void XamlObjectWriter.WriteStartMember(XamlMember property)
  ?, in void FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
System.Windows.Markup.XamlParseException: 给定关键字不在字典中。
  ?, in void XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
  ?, in void FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter) x 2
  ?, in DependencyObject FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List<DependencyObject> affectedChildren, UncommonField<Hashtable> templatedNonFeChildrenField)
  ?, in DependencyObject FrameworkTemplate.LoadContent(DependencyObject container, List<DependencyObject> affectedChildren)
  ?, in bool StyleHelper.ApplyTemplateContent(UncommonField<HybridDictionary[]> dataField, DependencyObject container, FrameworkElementFactory templateRoot, int lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
  ?, in bool FrameworkTemplate.ApplyTemplateContent(UncommonField<HybridDictionary[]> templateDataField, FrameworkElement container)
  ?, in bool FrameworkElement.ApplyTemplate()
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in Size Control.MeasureOverride(Size constraint)
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in Size Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
  ?, in Size ContentPresenter.MeasureOverride(Size constraint)
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in Size Border.MeasureOverride(Size constraint)
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in Size Border.MeasureOverride(Size constraint)
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in Size Decorator.MeasureOverride(Size constraint)
  ?, in Size ThemeShadowChrome.MeasureOverride(Size constraint)
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in Size Control.MeasureOverride(Size constraint)
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in Size AdornerDecorator.MeasureOverride(Size constraint)
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in Size Decorator.MeasureOverride(Size constraint)
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in Size PopupRoot.MeasureOverride(Size constraint)
  ?, in Size FrameworkElement.MeasureCore(Size availableSize)
  ?, in void UIElement.Measure(Size availableSize)
  ?, in void HwndSource.SetLayoutSize()
  ?, in void HwndSource.set_RootVisualInternal(Visual value)
  ?, in void Popup.SetRootVisualToPopupRoot()
  ?, in void Popup.CreateWindow(bool asyncCall)
  ?, in void Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  ?, in void DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  ?, in void FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  ?, in void DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
  ?, in UpdateResult DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, ref EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, Op...
  ?, in void DependencyObject.SetValueCommon(DependencyProperty dp, object value, PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, OperationType operationType, bool isInternal)
  ?, in BindingExpressionBase BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
  ?, in void Popup.CreateRootPopupInternal(Popup popup, UIElement child, bool bindTreatMousePlacementAsBottomProperty)
  ?, in void ToolTip.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  ?, in void DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  ?, in void FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  ?, in void DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
  ?, in UpdateResult DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, ref EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, Op...
  ?, in void DependencyObject.SetValueCommon(DependencyProperty dp, object value, PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, OperationType operationType, bool isInternal)
  ?, in void DependencyObject.SetValue(DependencyProperty dp, object value)
  ?, in void PopupControlService.RaiseToolTipOpeningEvent(bool fromKeyboard)
  ?, in object DispatcherTimer.FireTick(object unused)
  ?, in object ExceptionWrapper.InternalRealCall(Delegate callback, object args, int numArgs)
  ?, in object ExceptionWrapper.TryCatchWhen(object source, Delegate callback, object args, int numArgs, Delegate catchHandler)

Partial stacktrace in standard `Exception.ToString()` format
Unhandled exception from Application.DispatcherUnhandledException
System.Windows.Markup.XamlParseException: 给定关键字不在字典中。 ---> System.Collections.Generic.KeyNotFoundException: 给定关键字不在字典中。
   在 System.ThrowHelper.ThrowKeyNotFoundException()
   在 System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   在 XAMLMarkupExtensions.Base.TargetObjectsList.AddTargetObjectProperty(WeakReference targetObjectWeakReference, Object targetProperty, Type targetPropertyType, Int32 targetPropertyIndex) 位置 D:\a\XAMLMarkupExtensions\XAMLMarkupExtensions\src\Base\TargetObjectsList.cs:行号 82
   在 XAMLMarkupExtensions.Base.NestedMarkupExtension.ProvideValue(IServiceProvider serviceProvider) 位置 D:\a\XAMLMarkupExtensions\XAMLMarkupExtensions\src\Base\NestedMarkupExtension.cs:行号 286
   在 System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
   在 System.Windows.StyleHelper.GetChildValueHelper(UncommonField`1 dataField, ItemStructList`1& valueLookupList, DependencyProperty dp, DependencyObject container, FrameworkObject child, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
   在 System.Windows.StyleHelper.GetChildValue(UncommonField`1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
   在 System.Windows.StyleHelper.GetValueFromTemplatedParent(DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, FrameworkElementFactory templateRoot, EffectiveValueEntry& entry)
   在 System.Windows.StyleHelper.ApplyTemplatedParentValue(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, DependencyProperty dp, FrameworkElementFactory templateRoot)
   在 System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
   在 System.Windows.FrameworkTemplate.InvalidatePropertiesOnTemplate(DependencyObject container, Object currentObject)
   在 System.Windows.FrameworkTemplate.HandleBeforeProperties(Object createdObject, DependencyObject& rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
   在 System.Windows.FrameworkTemplate.<>c__DisplayClass45_0.<LoadOptimizedTemplateContent>b__2(Object sender, XamlObjectEventArgs args)
   在 System.Xaml.XamlObjectWriter.OnBeforeProperties(Object value)
   在 System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
   在 System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
   在 System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   在 System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   在 System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
   在 System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
   在 System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
   在 System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
   在 System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
   在 System.Windows.FrameworkElement.ApplyTemplate()
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 System.Windows.Controls.Control.MeasureOverride(Size constraint)
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   在 System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 System.Windows.Controls.Border.MeasureOverride(Size constraint)
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 System.Windows.Controls.Border.MeasureOverride(Size constraint)
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
   在 ModernWpf.Controls.Primitives.ThemeShadowChrome.MeasureOverride(Size constraint)
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 System.Windows.Controls.Control.MeasureOverride(Size constraint)
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 System.Windows.Controls.Primitives.PopupRoot.MeasureOverride(Size constraint)
   在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   在 System.Windows.UIElement.Measure(Size availableSize)
   在 System.Windows.Interop.HwndSource.SetLayoutSize()
   在 System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   在 System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot()
   在 System.Windows.Controls.Primitives.Popup.CreateWindow(Boolean asyncCall)
   在 System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   在 System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   在 System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   在 System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   在 System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   在 System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   在 System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
   在 System.Windows.Controls.Primitives.Popup.CreateRootPopupInternal(Popup popup, UIElement child, Boolean bindTreatMousePlacementAsBottomProperty)
   在 System.Windows.Controls.ToolTip.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   在 System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)

Hi, @Genteure. Could you check 3.9.1? It seems like #313, which has been fixed

Ohh you're right, not sure how I missed that.
I'll release a new version of my app this week.
Closing for now, I'll reopen if crashes still happens.