dotnet/wpf · error · ArgumentException
SR.CollectionView_WrongType
Error message
SR.CollectionView_WrongType
What it means
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.
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
Example fix
// before viewManager.GetViewRecord(collection, typeof(object), true, true); // after viewManager.GetViewRecord(collection, typeof(ListCollectionView), true, true);
Defensive patterns
Strategy: validation
Validate before calling
if (!typeof(System.ComponentModel.ICollectionView).IsAssignableFrom(collectionViewType)) throw new ArgumentException($"{collectionViewType.Name} must implement ICollectionView"); Type guard
static bool IsValidViewType(Type t) => t != null && typeof(System.ComponentModel.ICollectionView).IsAssignableFrom(t);
Try / catch
try { var rec = GetViewRecord(col, viewType, ...); } catch (ArgumentException ex) when (ex.Message.Contains("ICollectionView")) { viewType = typeof(ListCollectionView); } Prevention
- Always pass view types derived from ICollectionView
- Prefer not specifying a custom view type and use the default
- Unit-test custom view registrations
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.CannotMoveToUnknownPosition
- SR.CollectionView_NameTypeDuplicity
- SR.Format(SR.UnexpectedCollectionChangeAction, e.Action)
- SR.RemovedItemNotFound
- ' ' is not a valid value for ' '.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/9fa93ae639211b6c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs:579
else
icv = new ListCollectionView(il);
}
else
{
// collection is not IList, wrap it
IEnumerable ie = collection as IEnumerable;
if (ie != null)
{
icv = new EnumerableCollectionView(ie);
}
}
}
}
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 tablesView on GitHub (pinned to 81131a70a4)