I have a block of code that creates a single selection object from the selections of each layer of a Group Layer. This worked fine in Pro 3.1 but now in the process of updating to 3.3 and it is failing with "ArcGIS.Core.ObjectDisconnectedException: 'This object has been previously disposed and cannot be manipulated.'" despite all objects having _disposed as false.
The original layer is a nested group layer, groups within groups. It fails when there are selections in both of the nested groups being combined.
private Selection GetSelectionFromGroupLayer(Layer inputLayer)
{
Selection featureSelection = null;
var groupLayer = (GroupLayer)inputLayer;
IList<Layer> groupLayers = groupLayer.GetLayersAsFlattenedList().ToList();
for (int i = 0; i < groupLayers.Count; i++)
{
var layer = groupLayers[i];
if (layer is FeatureLayer)
{
var featureLayer = (FeatureLayer)layer;
if (featureLayer.SelectionCount != 0)
{
if (featureSelection == null)
{
featureSelection = featureLayer.GetSelection();
}
else
{
Selection selection = featureLayer.GetSelection();
//fails here
featureSelection = featureSelection.Combine(selection, SetOperation.Intersection);
}
}
featureLayer = null;
}
layer = null;
}
return featureSelection;
} Any suggestions?