{"record":{"id":"23ded8b888b88eca","repo":"dotnet/wpf","slug":"sr-collectionview-nametypeduplicity","errorCode":null,"errorMessage":"SR.CollectionView_NameTypeDuplicity","messagePattern":"SR\\.CollectionView_NameTypeDuplicity","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs","lineNumber":837,"sourceCode":"            {\n                this.Remove(al[k]);\n            }\n\n            return (al.Count > 0 || foundViewTableDirt);\n        }\n\n        private void ValidateViewType(CollectionView cv, Type collectionViewType)\n        {\n            if (collectionViewType != null)\n            {\n                // If the view contained in the ViewTable is a proxy of another\n                // view, then what we really want to compare is the type of that\n                // other view.\n                CollectionViewProxy cvp = cv as CollectionViewProxy;\n                Type cachedViewType = (cvp == null) ? cv.GetType() : cvp.ProxiedView.GetType();\n\n                if (cachedViewType != collectionViewType)\n                    throw new ArgumentException(SR.Format(SR.CollectionView_NameTypeDuplicity, collectionViewType, cachedViewType));\n            }\n        }\n\n        private HybridDictionary _inactiveViewTables = new HybridDictionary();\n        private static object StaticObject = new object();\n        internal static WeakReference StaticWeakRef = new WeakReference(StaticObject);\n        internal static WeakReference NullWeakRef = new WeakReference(null);\n    }\n\n    #endregion ViewManager\n}\n\n","sourceCodeStart":819,"sourceCodeEnd":850,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs#L819-L850","documentation":"ViewManager registers views keyed by (name, type); if a view already cached under the same key has a different concrete view type than the requested collectionViewType, it throws this ArgumentException. Registering the same collection twice with conflicting view types is ambiguous and unsupported.","triggerScenarios":"Calling a view-registration API with the same collection and key twice, first with view type A (e.g. ListCollectionView) and later with type B (e.g. BindingListCollectionView or a custom view).","commonSituations":"Collection data changing so a different default view is created between registrations; mixing two frameworks that each supply their own view type for the same collection; re-registering after the collection instance changed.","solutions":["Use the same collectionViewType for all registrations of the same collection+key","Release/unregister the existing view before registering with a different type","Keep the underlying collection instance stable; if it changed, treat it as a new registration key","Log the previous registration so conflicting registrations are caught early"],"exampleFix":"// before\nGetViewRecord(list, typeof(BindingListCollectionView), ...); // list already has ListCollectionView\n// after\nGetViewRecord(list, typeof(ListCollectionView), ...);","handlingStrategy":"validation","validationCode":"if (existingView != null && existingView.GetType() != requestedViewType) throw new InvalidOperationException(\"View already registered with a different type\");","typeGuard":"static bool IsSameViewType(ICollectionView cached, Type requested) { var t = (cached as CollectionViewProxy)?.ProxiedView?.GetType() ?? cached.GetType(); return t == requested; }","tryCatchPattern":"try { RegisterView(col, key, viewType); } catch (ArgumentException ex) { UnregisterView(key); RegisterView(col, key, viewType); }","preventionTips":["Use one canonical view type per collection","Centralize view registration in one place","Avoid re-registering the same collection with different view types"],"tags":["wpf","data-binding","conflict","collectionview"],"backgroundTag":"conflicting-config-options","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"}