{"record":{"id":"8cb07bee32efa22e","repo":"AvaloniaUI/Avalonia","slug":"collection-8cb07b","errorCode":null,"errorMessage":"collection","messagePattern":"collection","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"info","filePath":"src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs","lineNumber":17,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\n\nnamespace Avalonia.Collections.Pooled\n{\n    internal sealed class ICollectionDebugView<T>\n    {\n        private readonly ICollection<T> _collection;\n\n        public ICollectionDebugView(ICollection<T> collection)\n        {\n            _collection = collection ?? throw new ArgumentNullException(nameof(collection));\n        }\n\n        [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]\n        public T[] Items\n        {\n            get\n            {\n                T[] items = new T[_collection.Count];\n                _collection.CopyTo(items, 0);\n                return items;\n            }\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs#L1-L32","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Initialize the collection field so it is non-null by the time you inspect it.","Treat it as noise: this throw comes from the debugger proxy, not your code path — it does not occur at runtime.","If seen in a unit test that constructs the proxy, pass a non-null collection."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Debugger-only proxy; not reachable in normal code. Ensure fields are non-null before inspection.\n// No runtime validation needed; initialize your collection fields.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize collection fields at declaration or in the constructor.","Recognize that throws from ICollectionDebugView appear only in the debugger, not at runtime.","Do not construct this internal proxy directly in product code."],"tags":["csharp","debug","debugger-type-proxy","null-argument","pooled"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}