{"record":{"id":"8b7054abe41c7795","repo":"dotnet/wpf","slug":"sr-collectionview-viewtypeinsufficient","errorCode":null,"errorMessage":"SR.CollectionView_ViewTypeInsufficient","messagePattern":"SR\\.CollectionView_ViewTypeInsufficient","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs","lineNumber":592,"sourceCode":"            }\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\n            if (icv != null)\n            {\n                // if the view doesn't derive from CollectionView, create a proxy that does\n                CollectionView cv = icv as CollectionView;\n                if (cv == null)\n                    cv = new CollectionViewProxy(icv);\n\n                if (ilsList != null)    // IListSource's list shares the same view\n                    viewRecord = CacheView(ilsList, cvs, cv, null);\n\n                viewRecord = CacheView(collection, cvs, cv, viewRecord);\n\n                // raise the event for a new view","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs#L574-L610","documentation":"ViewManager throws this ArgumentException when it tries to instantiate the requested collectionViewType with Activator.CreateInstance and the type has no public constructor taking the collection (MissingMethodException). A usable ICollectionView must be constructible from a single collection argument.","triggerScenarios":"Registering/obtaining a view with a custom collectionViewType whose constructor does not accept the collection (wrong signature, no public ctor, or ctor parameter type incompatible with the actual collection instance).","commonSituations":"Custom CollectionView subclasses with extra constructor parameters; view types designed for a different collection type; refactors that changed the collection type without updating the view type.","solutions":["Add a public constructor to the custom view type that accepts the collection: public MyView(IEnumerable list)","Pass a view type whose constructor matches the collection (e.g. ListCollectionView for IList)","If the collection is not IList, derive from CollectionView and ensure the ctor signature matches","Fall back to the default view by not specifying collectionViewType"],"exampleFix":"// before\npublic class MyView { public MyView(object[] items) {} }\n// after\npublic class MyView : CollectionView { public MyView(IList list) : base(list) {} }","handlingStrategy":"validation","validationCode":"var ctor = collectionViewType.GetConstructor(new[]{ collection.GetType() }) ?? collectionViewType.GetConstructor(new[]{ typeof(object) }); if (ctor == null) throw new InvalidOperationException(\"View type has no compatible ctor\");","typeGuard":"static bool IsConstructibleView(Type v, object col) => v.GetConstructor(new[]{ col.GetType() }) != null || v.GetConstructor(new[]{ typeof(object) }) != null;","tryCatchPattern":"try { icv = CreateView(viewType, col); } catch (ArgumentException ex) { icv = new ListCollectionView((IList)col); }","preventionTips":["Custom CollectionView subclasses must expose a public ctor taking the collection","Keep ctor signatures aligned with the collection types they serve","Add a reflection-based test asserting the view type is constructible"],"tags":["wpf","data-binding","reflection","constructor"],"backgroundTag":"invalid-constructor-argument","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"}