dotnet/wpf · error · InvalidOperationException
SR.DataGrid_AutomationInvokeFailed
Error message
SR.DataGrid_AutomationInvokeFailed
What it means
DataGridCellItemAutomationPeer.Invoke implements IInvokeProvider.Invoke for a DataGrid cell. It attempts to invoke/activate the cell (and for NewItemPlaceholder rows, create a new item). If the invoke did not succeed and the cell is not a NewItemPlaceholder, the peer throws InvalidOperationException with SR.DataGrid_AutomationInvokeFailed, meaning the cell could not be programmatically activated.
Solutions
- Ensure the target column/cell is editable (DataGridColumn.IsReadOnly == false and DataGrid.IsReadOnly == false) before invoking.
- Handle InvalidOperationException from Invoke and fall back to selection (ISelectionItemProvider.Select) instead of invocation.
- Do not call Invoke on NewItemPlaceholder rows; detect the placeholder via Item and skip it.
- Verify the DataGrid is loaded, realized, and the cell is in view before invoking from an automation client.
Example fix
// before (automation client)
var invoke = (IInvokeProvider)cellPattern;
invoke.Invoke(); // throws on non-editable cell
// after
if (column.IsReadOnly) { selection.Select(); } else { invoke.Invoke(); } Defensive patterns
Strategy: try-catch
Validate before calling
if (dataGrid.IsReadOnly || column.IsReadOnly) { /* skip Invoke */ } Type guard
bool IsInvocable(DataGridCellItemAutomationPeer peer) => peer?.OwningDataGrid != null && !peer.OwningDataGrid.IsReadOnly;
Try / catch
try { ((IInvokeProvider)peer).Invoke(); } catch (InvalidOperationException ex) { /* fall back to Select */ } Prevention
- Check column/dataGrid read-only state before Invoke
- Skip NewItemPlaceholder rows
- Ensure the cell is scrolled into view
- Fall back to selection patterns
When it happens
Trigger: Calling Invoke() via UI Automation (IInvokeProvider) on a DataGrid cell whose OwningDataGrid.BeginEdit/activation path fails — e.g. the cell cannot enter edit mode, the DataGrid is not editable, or the underlying item cannot be activated — while the cell is not a NewItemPlaceholder row.
Common situations: UI Automation tests or screen readers invoking a read-only cell; invoking cells in a DataGrid whose columns are all read-only or whose IsReadOnly is true; invoking a cell in a templated/custom row where activation fails; automation scripts against DataGrids expecting rows (not cells) to be invocable.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- SR.DataGrid_CannotSelectCell
- SR.DataGrid_ColumnIsReadOnly
- SR.DataGridColumnHeaderItemAutomationPeer_Unresizable
- SR.DataGridColumnHeaderItemAutomationPeer_Unsupported
- SR.PropertyNotSupported
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/60b91b5ad6f50d91.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridCellItemAutomationPeer.cs:650
// other cells may need to be de-selected, let the DataGrid handle that.
this.OwningDataGrid.HandleSelectionForCellInput(cell, /* startDragging = */ false, /* allowsExtendSelect = */ false, /* allowsMinimalSelect = */ false);
// the cell is now the datagrid's "current" cell, so BeginEdit will put
// it into edit mode
success = this.OwningDataGrid.BeginEdit();
}
else
{
success = true;
}
}
// Invoke on a NewItemPlaceholder row creates a new item.
// BeginEdit on a NewItemPlaceholder row returns false.
if (!success && !IsNewItemPlaceholder)
{
throw new InvalidOperationException(SR.DataGrid_AutomationInvokeFailed);
}
}
#endregion
#region IScrollItemProvider
void IScrollItemProvider.ScrollIntoView()
{
this.OwningDataGrid.ScrollIntoView(Item, _column);
}
#endregion
#region ISelectionItemProvider
bool ISelectionItemProvider.IsSelected
{View on GitHub (pinned to 81131a70a4)