dotnet/wpf · error · ArgumentException

SR.CollectionView_NameTypeDuplicity

Error message

SR.CollectionView_NameTypeDuplicity

What it means

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.

Solutions

  1. Use the same collectionViewType for all registrations of the same collection+key
  2. Release/unregister the existing view before registering with a different type
  3. Keep the underlying collection instance stable; if it changed, treat it as a new registration key
  4. Log the previous registration so conflicting registrations are caught early

Example fix

// before
GetViewRecord(list, typeof(BindingListCollectionView), ...); // list already has ListCollectionView
// after
GetViewRecord(list, typeof(ListCollectionView), ...);
Defensive patterns

Strategy: validation

Validate before calling

if (existingView != null && existingView.GetType() != requestedViewType) throw new InvalidOperationException("View already registered with a different type");

Type guard

static bool IsSameViewType(ICollectionView cached, Type requested) { var t = (cached as CollectionViewProxy)?.ProxiedView?.GetType() ?? cached.GetType(); return t == requested; }

Try / catch

try { RegisterView(col, key, viewType); } catch (ArgumentException ex) { UnregisterView(key); RegisterView(col, key, viewType); }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/23ded8b888b88eca. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs:837

            {
                this.Remove(al[k]);
            }

            return (al.Count > 0 || foundViewTableDirt);
        }

        private void ValidateViewType(CollectionView cv, Type collectionViewType)
        {
            if (collectionViewType != null)
            {
                // If the view contained in the ViewTable is a proxy of another
                // view, then what we really want to compare is the type of that
                // other view.
                CollectionViewProxy cvp = cv as CollectionViewProxy;
                Type cachedViewType = (cvp == null) ? cv.GetType() : cvp.ProxiedView.GetType();

                if (cachedViewType != collectionViewType)
                    throw new ArgumentException(SR.Format(SR.CollectionView_NameTypeDuplicity, collectionViewType, cachedViewType));
            }
        }

        private HybridDictionary _inactiveViewTables = new HybridDictionary();
        private static object StaticObject = new object();
        internal static WeakReference StaticWeakRef = new WeakReference(StaticObject);
        internal static WeakReference NullWeakRef = new WeakReference(null);
    }

    #endregion ViewManager
}

View on GitHub (pinned to 81131a70a4)