{"record":{"id":"60b91b5ad6f50d91","repo":"dotnet/wpf","slug":"sr-datagrid-automationinvokefailed","errorCode":null,"errorMessage":"SR.DataGrid_AutomationInvokeFailed","messagePattern":"SR\\.DataGrid_AutomationInvokeFailed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridCellItemAutomationPeer.cs","lineNumber":650,"sourceCode":"\n                    // other cells may need to be de-selected, let the DataGrid handle that.\n                    this.OwningDataGrid.HandleSelectionForCellInput(cell, /* startDragging = */ false, /* allowsExtendSelect = */ false, /* allowsMinimalSelect = */ false);\n\n                    // the cell is now the datagrid's \"current\" cell, so BeginEdit will put\n                    // it into edit mode\n                    success = this.OwningDataGrid.BeginEdit();\n                }\n                else\n                {\n                    success = true;\n                }\n            }\n\n            // Invoke on a NewItemPlaceholder row creates a new item.\n            // BeginEdit on a NewItemPlaceholder row returns false.\n            if (!success  && !IsNewItemPlaceholder)\n            {\n                throw new InvalidOperationException(SR.DataGrid_AutomationInvokeFailed);\n            }\n        }\n\n        #endregion\n\n        #region IScrollItemProvider\n\n        void IScrollItemProvider.ScrollIntoView()\n        {\n            this.OwningDataGrid.ScrollIntoView(Item, _column);\n        }\n\n        #endregion\n\n        #region ISelectionItemProvider\n\n        bool ISelectionItemProvider.IsSelected\n        {","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridCellItemAutomationPeer.cs#L632-L668","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (automation client)\nvar invoke = (IInvokeProvider)cellPattern;\ninvoke.Invoke(); // throws on non-editable cell\n\n// after\nif (column.IsReadOnly) { selection.Select(); } else { invoke.Invoke(); }","handlingStrategy":"try-catch","validationCode":"if (dataGrid.IsReadOnly || column.IsReadOnly) { /* skip Invoke */ }","typeGuard":"bool IsInvocable(DataGridCellItemAutomationPeer peer) => peer?.OwningDataGrid != null && !peer.OwningDataGrid.IsReadOnly;","tryCatchPattern":"try { ((IInvokeProvider)peer).Invoke(); } catch (InvalidOperationException ex) { /* fall back to Select */ }","preventionTips":["Check column/dataGrid read-only state before Invoke","Skip NewItemPlaceholder rows","Ensure the cell is scrolled into view","Fall back to selection patterns"],"tags":["wpf","automation","datagrid","invoke"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}