AvaloniaUI/Avalonia · info · ArgumentNullException

collection

Error message

collection

What it means

Constructor null guard in the internal ICollectionDebugView<T> debugger proxy. It throws ArgumentNullException("collection") when constructed with a null ICollection<T>. This type is a DebuggerTypeProxy used only by the IDE/watch windows to render a pooled collection; it is not part of the runtime API surface a user calls directly.

Source

Thrown at src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs:17

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Avalonia.Collections.Pooled
{
    internal sealed class ICollectionDebugView<T>
    {
        private readonly ICollection<T> _collection;

        public ICollectionDebugView(ICollection<T> collection)
        {
            _collection = collection ?? throw new ArgumentNullException(nameof(collection));
        }

        [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
        public T[] Items
        {
            get
            {
                T[] items = new T[_collection.Count];
                _collection.CopyTo(items, 0);
                return items;
            }
        }
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Initialize the collection field so it is non-null by the time you inspect it.
  2. Treat it as noise: this throw comes from the debugger proxy, not your code path — it does not occur at runtime.
  3. If seen in a unit test that constructs the proxy, pass a non-null collection.
Defensive patterns

Strategy: validation

Validate before calling

// Debugger-only proxy; not reachable in normal code. Ensure fields are non-null before inspection.
// No runtime validation needed; initialize your collection fields.

Prevention

When it happens

Trigger: The debugger instantiates ICollectionDebugView for a collection field/variable that evaluates to null while inspecting Locals/Watch. Direct instantiation (`new ICollectionDebugView<T>(null)`) only happens in tests or manual debugging.

Common situations: Inspecting a null ICollection<T> field in the debugger; an uninitialized PooledList/List field shown in Locals before it has been assigned. The throw is debugger-only and will not surface in a normal program run.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/8cb07bee32efa22e. Report an issue: GitHub.