{"record":{"id":"f5eb8829e5dc67a3","repo":"dotnet/wpf","slug":"sr-listview-gridviewcolumncollectionisreadonly","errorCode":null,"errorMessage":"SR.ListView_GridViewColumnCollectionIsReadOnly","messagePattern":"SR\\.ListView_GridViewColumnCollectionIsReadOnly","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnCollection.cs","lineNumber":439,"sourceCode":"            ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, _actualIndices.Count, indexName);\n        }\n\n        // Throw if column is null or already existed in a GVCC\n        private void ValidateColumnForInsert(GridViewColumn column)\n        {\n            ArgumentNullException.ThrowIfNull(column);\n\n            if (column.ActualIndex >= 0)\n            {\n                throw new InvalidOperationException(SR.ListView_NotAllowShareColumnToTwoColumnCollection);\n            }\n        }\n\n        private void VerifyAccess()\n        {\n            if (IsImmutable)\n            {\n                throw new InvalidOperationException(SR.ListView_GridViewColumnCollectionIsReadOnly);\n            }\n\n            // Although CheckReentrancy() is called in base class, we still need to call it here again,\n            // otherwise, when Reentrancy is found and exception is thrown, our operation is done and can't be undo.\n            CheckReentrancy();\n        }\n\n        #endregion\n\n        //------------------------------------------------------\n        //\n        //  Private Fields\n        //\n        //------------------------------------------------------\n\n        #region Private Fields\n\n        // internal storage of CollumnCollection","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/GridViewColumnCollection.cs#L421-L457","documentation":"Thrown by GridViewColumnCollection.VerifyAccess when the collection is immutable (IsImmutable) and a mutating operation (Clear/Remove/Insert/Set/Move) is attempted. A GridViewColumnCollection becomes immutable once it is in use by an attached GridView, typically during layout or when the view has been applied. It guards read-only collection state against structurally invalid mutations.","triggerScenarios":"Calling Add/Insert/Remove/Clear/Move/SetItem on a GridViewColumnCollection whose IsImmutable is true — commonly a collection that already belongs to an attached GridView or is accessed during a layout/property-changed pass.","commonSituations":"Modifying GridView.Columns from a background thread or inside a rendering/layout callback; attempting to edit a collection after the GridView has been applied to a ListView in certain deferred states; reentrancy during a column change notification.","solutions":["Perform modifications on the UI thread and outside of layout (e.g. via Dispatcher.BeginInvoke at Background priority or later)","Check collection ownership state before mutating; defer changes until after the view is applied","Reentrancy: complete the in-progress column change before issuing another mutation"],"exampleFix":"// before\nvoid OnLoaded(object s, RoutedEventArgs e) => gridView.Columns.Add(newColumn); // may run during layout\n// after\nvoid OnLoaded(object s, RoutedEventArgs e) => Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => gridView.Columns.Add(newColumn)));","handlingStrategy":"validation","validationCode":"// queue mutation off-layout\nDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => gridView.Columns.Add(col)));","typeGuard":"null","tryCatchPattern":"try { gridView.Columns.Add(col); } catch (InvalidOperationException ex) { Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => gridView.Columns.Add(col))); }","preventionTips":["Mutate the column collection only on the UI thread and outside layout passes","Avoid mutating columns from within property-changed or rendering callbacks","Re-check ownership/attachment state before structural edits"],"tags":["wpf","gridview","collection-readonly","threading"],"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"}