wpf: Crash due to exception "Height must be non-negative."
- .NET Core Version: 4.8 and 4.8.1
- Windows version: 22H2
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
- Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc…)? No.
Problem description: Crash related to updating an ObservableCollection in WPF. Started occurring after recent application of update KB5017271. The issue was not occurring before this. Crashing has also been observed on Windows 10 machines, after the application of KB5017497. Our application has not been updated. Crash appears to be related to these .NET updates.
Actual behavior: Call stacks are all identical:
at System.Windows.Size.set_Height(Double value)\r\n
at System.Windows.Controls.VirtualizingStackPanel.AdjustEffectiveOffsetForItemsChange(ItemsChangedEventArgs args)\r\n
at System.Windows.Controls.VirtualizingStackPanel.ShouldItemsChangeAffectLayoutCore(Boolean areItemChangesLocal, ItemsChangedEventArgs args)\r\n
at System.Windows.Controls.VirtualizingPanel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args)\r\n
at System.Windows.Controls.Panel.OnItemsChanged(Object sender, ItemsChangedEventArgs args)\r\n
at System.Windows.Controls.ItemContainerGenerator.OnItemRemoved(Object item, Int32 itemIndex, NotifyCollectionChangedEventArgs collectionChangedArgs)\r\n
at System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)\r\n
at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)\r\n
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)\r\n
at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)\r\n
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)\r\n
at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)\r\n
at System.Windows.Controls.ItemCollection.OnViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)\r\n
at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)\r\n
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)\r\n
at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)\r\n
at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)\r\n
at System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args, Int32 adjustedOldIndex, Int32 adjustedNewIndex)\r\n
at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)\r\n
at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)\r\n
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index)\r\n
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (7 by maintainers)
@billhenn - The issue has been fixed on .NET Framework and will be available in upcoming servicing updates.
@dipeshmsft I can confirm the issue is no longer reproducible in our Sample Browser application on Win10 22H2 after applying the January .NET Framework update. Thank you for helping get this issue resolved!
@Pierre-Alianza, @MorfMichael, @boydpatterson, we have tried to fix this issue in the latest windows release, can you please remove the opt-out switch and check if the applications are working as they used to work before ?
A user of our controls who has been bitten by this .NET Framework bug let us know about a workaround that Microsoft shared with him on the issue, so I wanted to repost it here for others. The response was to use an
AppContextswitch as demonstrated in the following snippet:I hope this can help some others until the fix is released.
Cool, thank you @boydpatterson, I confirm this reproduces the issue for me.
This issue was brought to our attention by one of our customers who began seeing the same stack trace on test machines after receiving the already mentioned update. We have been able to consistently reproduce this issue in a sample application we provide for evaluating our controls. The issue was reproduced with .NET Framework 4.8, but the same steps did not reproduce the issue with .NET 5. Turning off virtualization (
VirtualizingPanel.IsContainerVirtualizable="False") also prevents the exception from being raised.Since it is unclear whether or not this issue has been reproduced internally, we wanted to offer up our sample application and the following steps to help reproduce and resolve this issue.
Acquire the Actipro WPF Controls Sample Browser from our public repo: https://github.com/Actipro/WPF-Controls
At this point, the following stack trace was reported on Windows 11 using .NET Framework 4.8:
Thanks, @boydpatterson @MorfMichael for the confirmation. I will go ahead and close the issue.
For Windows 11 uninstalling KB5017271 resolves the crash. For more information: the ObservableCollection is used as the ItemsSource for a ListView.
Do you have a repro project?
Looks similar to #2854.