{"record":{"id":"d621c5107182690e","repo":"dotnet/wpf","slug":"sr-nocheckorchangewhendeferred-collectionview","errorCode":null,"errorMessage":"SR.NoCheckOrChangeWhenDeferred","messagePattern":"SR\\.NoCheckOrChangeWhenDeferred","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs","lineNumber":1422,"sourceCode":"        internal virtual bool HasReliableHashCodes()\n        {\n            // default implementation - sample the first item\n            return (IsEmpty || HashHelper.HasReliableHashCode(GetItemAt(0)));\n        }\n\n        // helper to validate that we are not in the middle of a DeferRefresh\n        // and throw if that is the case.\n        internal void VerifyRefreshNotDeferred()\n        {\n            if (AllowsCrossThreadChanges)\n                VerifyAccess();\n\n            // If the Refresh is being deferred to change filtering or sorting of the\n            // data by this CollectionView, then CollectionView will not reflect the correct\n            // state of the underlying data.\n\n            if (IsRefreshDeferred)\n                throw new InvalidOperationException(SR.NoCheckOrChangeWhenDeferred);\n        }\n\n        internal void InvalidateEnumerableWrapper()\n        {\n            IndexedEnumerable wrapper = (IndexedEnumerable) Interlocked.Exchange(ref _enumerableWrapper, null);\n            wrapper?.Invalidate();\n        }\n\n        internal ReadOnlyCollection<ItemPropertyInfo> GetItemProperties()\n        {\n            IEnumerable collection = SourceCollection;\n            if (collection == null)\n                return null;\n\n            IEnumerable properties = null;\n\n            ITypedList itl = collection as ITypedList;\n            Type itemType;","sourceCodeStart":1404,"sourceCodeEnd":1440,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs#L1404-L1440","documentation":"CollectionView throws InvalidOperationException (SR.NoCheckOrChangeWhenDeferred) when callers attempt to check or change currency (e.g. via VerifyRefreshNotDeferred) while a Refresh is deferred through DeferRefresh. During a defer scope the view's state is intentionally stale, so currency operations and changes are rejected to avoid acting on incorrect data.","triggerScenarios":"Calling MoveCurrentTo*, MoveCurrentToPosition, or other currency/state-changing members while inside a using (collectionView.DeferRefresh()) block (IsRefreshDeferred == true).","commonSituations":"Batch-updating Filter/SortDescriptions inside a DeferRefresh scope and also trying to move current item; helper code that sets selection/currency while deferring refresh; nested helpers that open a defer scope around selection changes.","solutions":["Move current item before entering the DeferRefresh scope or after disposing the DeferHelper","Restructure code so currency operations happen outside the defer block","Check collectionView.IsRefreshDeferred and skip/postpone currency changes until the defer ends"],"exampleFix":"// before\nusing (view.DeferRefresh()) {\n    view.Filter = p;\n    view.MoveCurrentToFirst(); // InvalidOperationException\n}\n// after\nview.Filter = p;\nview.MoveCurrentToFirst();\n// or do currency changes after the using block","handlingStrategy":"validation","validationCode":"if (view.IsRefreshDeferred)\n    throw new InvalidOperationException(\"Refresh is deferred; postpone currency changes.\");\nview.MoveCurrentToFirst();","typeGuard":"bool currencySafe = view is CollectionView cv && !cv.IsRefreshDeferred;","tryCatchPattern":"try { view.MoveCurrentTo(item); }\ncatch (InvalidOperationException) { /* defer ended elsewhere */ view.MoveCurrentTo(item); }","preventionTips":["Keep currency operations outside using (DeferRefresh()) blocks","Track defer scopes in a helper so currency changes are queued until disposal","Check IsRefreshDeferred before MoveCurrent* calls"],"tags":["wpf","collectionview","deferred-refresh","currency"],"backgroundTag":"invalid-state-transition","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"}