{"record":{"id":"9fa93ae639211b6c","repo":"dotnet/wpf","slug":"sr-collectionview-wrongtype","errorCode":null,"errorMessage":"SR.CollectionView_WrongType","messagePattern":"SR\\.CollectionView_WrongType","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs","lineNumber":579,"sourceCode":"                        else\n                            icv = new ListCollectionView(il);\n                    }\n                    else\n                    {\n                        // collection is not IList, wrap it\n                        IEnumerable ie = collection as IEnumerable;\n                        if (ie != null)\n                        {\n                            icv = new EnumerableCollectionView(ie);\n                        }\n                    }\n                }\n            }\n            else\n            {\n                // caller specified a type for the view.  Try to honor it.\n                if (!typeof(ICollectionView).IsAssignableFrom(collectionViewType))\n                    throw new ArgumentException(SR.Format(SR.CollectionView_WrongType, collectionViewType.Name));\n\n                // if collection is IListSource, get its list first (bug 1023903)\n                object arg = ilsList ?? collection;\n\n                try\n                {\n                    icv = Activator.CreateInstance(collectionViewType,\n                                    System.Reflection.BindingFlags.CreateInstance, null,\n                                    new object[1] { arg }, null) as ICollectionView;\n                }\n                catch (MissingMethodException e)\n                {\n                    throw new ArgumentException(SR.Format(SR.CollectionView_ViewTypeInsufficient,\n                                    collectionViewType.Name, collection.GetType()), e);\n                }\n            }\n\n            // if we got a view, add it to the tables","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs#L561-L597","documentation":"ViewManager.RegisterViewAsync (GetViewRecord) throws this ArgumentException when the caller passes a collectionViewType that is not a type implementing ICollectionView. WPF requires every view it manages to be an ICollectionView; honoring an arbitrary type is impossible.","triggerScenarios":"Calling BindingOperations.GetView / ViewManager.GetViewRecord (e.g. via a CollectionViewSource.View or custom binding) with a collectionViewType parameter that does not derive from ICollectionView, such as typeof(object) or a custom non-view collection wrapper type.","commonSituations":"Custom markup extensions or third-party collection frameworks registering a wrong view type; copy-pasted code where the type parameter was changed to a base class; typos passing the collection's type instead of the view type.","solutions":["Pass a Type assignable to ICollectionView, e.g. typeof(ListCollectionView) or typeof(BindingListCollectionView)","If you need a custom view, implement ICollectionView (usually via CollectionView) and pass that type","Check the value passed as collectionViewType at the call site before invoking the binding/view API"],"exampleFix":"// before\nviewManager.GetViewRecord(collection, typeof(object), true, true);\n// after\nviewManager.GetViewRecord(collection, typeof(ListCollectionView), true, true);","handlingStrategy":"validation","validationCode":"if (!typeof(System.ComponentModel.ICollectionView).IsAssignableFrom(collectionViewType)) throw new ArgumentException($\"{collectionViewType.Name} must implement ICollectionView\");","typeGuard":"static bool IsValidViewType(Type t) => t != null && typeof(System.ComponentModel.ICollectionView).IsAssignableFrom(t);","tryCatchPattern":"try { var rec = GetViewRecord(col, viewType, ...); } catch (ArgumentException ex) when (ex.Message.Contains(\"ICollectionView\")) { viewType = typeof(ListCollectionView); }","preventionTips":["Always pass view types derived from ICollectionView","Prefer not specifying a custom view type and use the default","Unit-test custom view registrations"],"tags":["wpf","data-binding","argument-validation","collectionview"],"backgroundTag":"invalid-argument-value","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"}