Unplanned
Last Updated: 24 Mar 2025 10:49 by Martin Ivanov
Martin Ivanov
Created on: 24 Mar 2025 10:49
Category: GridView
Type: Bug Report
4
GridView: NullReferenceException when automation peers creation goes over the MaxCachedPeersSize value (10,000) and the item type that populates the ItemsSource uses the 'record' modifier

NullReferenceException occurs when the the automation peers creation for the rows goes over 10,000 peers (the MaxCachedPeersSize setting of the GridViewDataControlAutomationPeer). The exception occurs only when the 'record' modifier is used in the class definition. For example:

public record class MyClass(int Id)
{
}

The exception stacktrace is:

System.NullReferenceException: 'Object reference not set to an instance of an object.'
peer was null.
Telerik.Windows.Controls.GridView.dll!Telerik.Windows.Automation.Peers.GridViewDataControlAutomationPeer.ClearPeer(Telerik.Windows.Automation.Peers.DataItemAutomationPeer peer)   Telerik.Windows.Controls.GridView.dll!Telerik.Windows.Automation.Peers.GridViewDataControlAutomationPeer.GetOrCreateItemPeer(object item, int index) Line 288 C#  Telerik.Windows.Controls.GridView.dll!Telerik.Windows.Automation.Peers.GridViewRowAutomationPeer.FindDataItemAutomationPeer(System.Collections.Generic.List<System.Windows.Automation.Peers.AutomationPeer> childPeers) Telerik.Windows.Controls.GridView.dll!Telerik.Windows.Automation.Peers.GridViewRowAutomationPeer.GetChildrenCore() 

.

To work this around use the "class" modifier instead of "record". For example, instead of:

public record class MyClass(int Id)
{
}

Use:

public class MyClass
{
    public int Id { get; set; } 
}

 Or alternatively, increase the MaxCachedPeersSize value.

 

0 comments