Hashtable Load Factor Too High Exception
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
We are getting a XamlParseException thrown very intermittently when under high loads.
The application displays multiple windows. Each window is running on a separate dispatcher thread.
Occasionally multiple windows (but not all) on separate dispatcher threads will fail at the same time after throwing a UnhandledDispatcherException "Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.".
We have very high GUI update rates; potentially 20,000 to 50,000 updates per second spread across 3 or 4 windows.
This issue has been reported by other users previously: https://github.com/dotnet/wpf/issues/4168
### Reproduction Steps
I'm still working on a reliable reproduction. This error only appears occasionally across hundreds of users.
Please let me know if you have any ideas on how to go about getting a reproduction.
### Expected behavior
Performing GUI updates in separate windows on separate dispatchers should be thread safe and not cause failures.
### Actual behavior
An exception is thrown when under high loads
```
Dispatcher Unhandled Exception:
XamlParseException { LineNumber: 0, LinePosition: 0, KeyContext: null, UidContext: null, NameContext: null, BaseUri: null, TargetSite: Void RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri), Message: "Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.", Data: [DictionaryEntry { Key: Object { }, Value: null }], InnerException: InvalidOperationException { TargetSite: Void Insert(System.Object, System.Object, Boolean), Message: "Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.", Data: [], InnerException: null, HelpLink: null, Source: "System.Private.CoreLib", HResult: -2146233079, StackTrace: " at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at MS.Internal.Data.ValueChangedEventManager.AddListener(Object source, PropertyDescriptor pd, IWeakEventListener listener, EventHandler`1 handler)
at MS.Internal.Data.ValueChangedEventManager.AddHandler(Object source, EventHandler`1 handler, PropertyDescriptor pd)
at MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32 k, Object newO, Object parent)
at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
at MS.Internal.Data.ClrBindingWorker.AttachDataItem()
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp)
at System.Windows.Data.BindingExpressionBase.Attach(DependencyObject target, DependencyProperty dp)
at System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
at 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)
at System.Windows.StyleHelper.GetChildValue(UncommonField`1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.GetValueFromTemplatedParent(DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, FrameworkElementFactory templateRoot, EffectiveValueEntry& entry)
at System.Windows.StyleHelper.ApplyTemplatedParentValue(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, DependencyProperty dp, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
at System.Windows.FrameworkTemplate.InvalidatePropertiesOnTemplate(DependencyObject container, Object currentObject)
at System.Windows.FrameworkTemplate.<>c__DisplayClass45_0.b__2(Object sender, XamlObjectEventArgs args)
at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)" }, HelpLink: null, Source: "PresentationFramework", HResult: -2146233087, StackTrace: " at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.XamlReader.RewrapException(Exception e, Uri baseUri)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
at System.Windows.FrameworkElement.ApplyTemplate()
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)" }
```
### Regression?
_No response_
### Known Workarounds
_No response_
### Impact
_No response_
### Configuration
NET Version: NET 6
Operation System: Windows 10 / 11
Architecture: x64
Specific: Unknown
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.