I also have the same problem.
The problem occurs because I use the flag IsVirtualizingStackPanel_45Compatible which is intended to fix a performance problem, as described in https://social.msdn.microsoft.com/Forums/vstudio/en-US/c04c07de-883c-4801-ae24-0dd75f2ffe20/performance-issue-for-virtualizingstackpanel-in-net-461?forum=wpf
When the ListView/DataGrid contains enough items so that the scrollBar is displayed, any attempt to add another item causes a crash.
I created a small project that reproduces the problem: https://github.com/br25802580/ListView_Crash_KB5017270
This is the code that causes the problem to be reproduced:
XAML
<StackPanel Orientation="Vertical" Margin="40">
<Button HorizontalAlignment="Left" Click="AddItemBtn_Click">Add item</Button>
<ListView Grid.Row="2" x:Name="MyList"
HorizontalAlignment="Left"
Width="200"
MaxHeight="60">
</ListView>
</StackPanel>
XAML.cs
public MainWindow()
{
InitializeComponent();
MyList.Items.Add("111");
MyList.Items.Add("222");
MyList.Items.Add("333");
MyList.Items.Add("444");
}
private void AddItemBtn_Click(object sender, RoutedEventArgs e)
{
MyList.Items.Add("555");
}
App.config
<appSettings>
<add key="IsVirtualizingStackPanel_45Compatible" value="true" />
</appSettings>