{"record":{"id":"6698db9fd0368fc9","repo":"dotnet/wpf","slug":"sr-format-sr-implementothermemberswithsort-refresh","errorCode":null,"errorMessage":"SR.Format(SR.ImplementOtherMembersWithSort, \"Refresh()\")","messagePattern":"SR\\.Format\\(SR\\.ImplementOtherMembersWithSort, \"Refresh\\(\\)\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs","lineNumber":837,"sourceCode":"\n        #endregion Public Events\n\n\n        //------------------------------------------------------\n        //\n        //  Protected Methods\n        //\n        //------------------------------------------------------\n\n        #region Protected Methods\n\n        /// <summary>\n        /// Re-create the view, using any <seealso cref=\"SortDescriptions\"/> and/or <seealso cref=\"Filter\"/>.\n        /// </summary>\n        protected virtual void RefreshOverride()\n        {\n            if (SortDescriptions.Count > 0)\n                throw new InvalidOperationException(SR.Format(SR.ImplementOtherMembersWithSort, \"Refresh()\"));\n\n            object oldCurrentItem = _currentItem;\n            bool oldIsCurrentAfterLast = CheckFlag(CollectionViewFlags.IsCurrentAfterLast);\n            bool oldIsCurrentBeforeFirst = CheckFlag(CollectionViewFlags.IsCurrentBeforeFirst);\n            int oldCurrentPosition = _currentPosition;\n\n            // force currency off the collection (gives user a chance to save dirty information)\n            OnCurrentChanging();\n\n            InvalidateEnumerableWrapper();\n\n            if (IsEmpty || oldIsCurrentBeforeFirst)\n            {\n                _MoveCurrentToPosition(-1);\n            }\n            else if (oldIsCurrentAfterLast)\n            {\n                _MoveCurrentToPosition(Count);","sourceCodeStart":819,"sourceCodeEnd":855,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs#L819-L855","documentation":"The base CollectionView.RefreshOverride throws InvalidOperationException if SortDescriptions is non-empty. The base implementation does not perform sorting; a derived view must implement sorting (and allow SortDescriptions) itself, so calling Refresh on the base view while sort descriptions exist is an error rather than a silent no-op.","triggerScenarios":"Adding one or more SortDescriptions to a plain CollectionView (not a ListCollectionView or other sorted-capable derived view) and then triggering Refresh — e.g. by changing Filter, calling Refresh(), or the view being refreshed internally.","commonSituations":"Sorting an ItemsControl bound to a plain CollectionView over IEnumerable instead of ListCollectionView; custom CollectionView subclass overriding RefreshOverride without handling SortDescriptions.","solutions":["Use ListCollectionView (obtained via CollectionViewSource.GetDefaultView over an IList) which implements sorting","Clear SortDescriptions before refreshing a base CollectionView","Implement sorting in a custom view by overriding RefreshOverride to honor SortDescriptions","Sort the underlying collection directly instead of using view SortDescriptions"],"exampleFix":"// before\nvar view = (CollectionView)CollectionViewSource.GetDefaultView(enumerable); // not IList\nview.SortDescriptions.Add(new SortDescription(\"Name\", ListSortDirection.Ascending)); // throws on Refresh\n// after\nvar view = (ListCollectionView)CollectionViewSource.GetDefaultView(new ObservableCollection<T>(list));\nview.SortDescriptions.Add(new SortDescription(\"Name\", ListSortDirection.Ascending));","handlingStrategy":"validation","validationCode":"if (view is CollectionView cv && cv.SortDescriptions.Count > 0 && view.GetType() == typeof(CollectionView))\n    cv.SortDescriptions.Clear(); // or switch to ListCollectionView","typeGuard":"bool sortCapable = view is ListCollectionView || view.GetType() != typeof(CollectionView);","tryCatchPattern":"try { view.Refresh(); }\ncatch (InvalidOperationException) { view.SortDescriptions.Clear(); view.Refresh(); }","preventionTips":["Use ListCollectionView (IList-backed sources) whenever sorting via SortDescriptions is needed","Check CanSort before adding SortDescriptions","Avoid adding SortDescriptions to plain CollectionView over IEnumerable sources"],"tags":["wpf","collectionview","sorting","not-implemented"],"backgroundTag":"method-not-implemented","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"}