dotnet/wpf · error · ArgumentException
SR.CollectionView_ViewTypeInsufficient
Error message
SR.CollectionView_ViewTypeInsufficient
What it means
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.
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
Example fix
// before
public class MyView { public MyView(object[] items) {} }
// after
public class MyView : CollectionView { public MyView(IList list) : base(list) {} } Defensive patterns
Strategy: validation
Validate before calling
var ctor = collectionViewType.GetConstructor(new[]{ collection.GetType() }) ?? collectionViewType.GetConstructor(new[]{ typeof(object) }); if (ctor == null) throw new InvalidOperationException("View type has no compatible ctor"); Type guard
static bool IsConstructibleView(Type v, object col) => v.GetConstructor(new[]{ col.GetType() }) != null || v.GetConstructor(new[]{ typeof(object) }) != null; Try / catch
try { icv = CreateView(viewType, col); } catch (ArgumentException ex) { icv = new ListCollectionView((IList)col); } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- SR.ListView_MissingParameterlessConstructor
- ArgumentNullException
- ArgumentNullException(nameof(assemblyNames))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8b7054abe41c7795.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs:592
}
else
{
// caller specified a type for the view. Try to honor it.
if (!typeof(ICollectionView).IsAssignableFrom(collectionViewType))
throw new ArgumentException(SR.Format(SR.CollectionView_WrongType, collectionViewType.Name));
// if collection is IListSource, get its list first (bug 1023903)
object arg = ilsList ?? collection;
try
{
icv = Activator.CreateInstance(collectionViewType,
System.Reflection.BindingFlags.CreateInstance, null,
new object[1] { arg }, null) as ICollectionView;
}
catch (MissingMethodException e)
{
throw new ArgumentException(SR.Format(SR.CollectionView_ViewTypeInsufficient,
collectionViewType.Name, collection.GetType()), e);
}
}
// if we got a view, add it to the tables
if (icv != null)
{
// if the view doesn't derive from CollectionView, create a proxy that does
CollectionView cv = icv as CollectionView;
if (cv == null)
cv = new CollectionViewProxy(icv);
if (ilsList != null) // IListSource's list shares the same view
viewRecord = CacheView(ilsList, cvs, cv, null);
viewRecord = CacheView(collection, cvs, cv, viewRecord);
// raise the event for a new viewView on GitHub (pinned to 81131a70a4)