{"record":{"id":"967c04be92a7015b","repo":"AvaloniaUI/Avalonia","slug":"collection","errorCode":null,"errorMessage":"collection","messagePattern":"collection","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Collections/NotifyCollectionChangedExtensions.cs","lineNumber":18,"sourceCode":"﻿using System;\nusing System.Collections.Specialized;\nusing Avalonia.Reactive;\nusing Avalonia.Utilities;\n\nnamespace Avalonia.Collections\n{\n    public static class NotifyCollectionChangedExtensions\n    {\n        /// <summary>\n        /// Gets a weak observable for the CollectionChanged event.\n        /// </summary>\n        /// <param name=\"collection\">The collection.</param>\n        /// <returns>An observable.</returns>\n        public static IObservable<NotifyCollectionChangedEventArgs> GetWeakCollectionChangedObservable(\n            this INotifyCollectionChanged collection)\n        {\n            _ = collection ?? throw new ArgumentNullException(nameof(collection));\n\n            return new WeakCollectionChangedObservable(new WeakReference<INotifyCollectionChanged>(collection));\n        }\n\n        /// <summary>\n        /// Subscribes to the CollectionChanged event using a weak subscription.\n        /// </summary>\n        /// <param name=\"collection\">The collection.</param>\n        /// <param name=\"handler\">\n        /// An action called when the collection event is raised.\n        /// </param>\n        /// <returns>A disposable used to terminate the subscription.</returns>\n        public static IDisposable WeakSubscribe(\n            this INotifyCollectionChanged collection, \n            NotifyCollectionChangedEventHandler handler)\n        {\n            _ = collection ?? throw new ArgumentNullException(nameof(collection));\n            _ = handler ?? throw new ArgumentNullException(nameof(handler));","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Collections/NotifyCollectionChangedExtensions.cs#L1-L36","documentation":"ArgumentNullException thrown by NotifyCollectionChangedExtensions.GetWeakCollectionChangedObservable when the source collection is null. The extension creates a WeakCollectionChangedObservable holding a WeakReference to the collection and requires a live target.","triggerScenarios":"Calling collection.GetWeakCollectionChangedObservable() where the 'collection' receiver (the 'this' argument) is null; passing null explicitly as the INotifyCollectionChanged argument.","commonSituations":"A collection property that is null when subscribed to (lazy/not-yet-initialized); a binding/reactive chain that forwards a null collection reference into the weak-subscribe path.","solutions":["Ensure the collection is non-null before calling the extension (guard the call site).","Initialize the collection property before wiring subscriptions.","Null-check and skip/return an empty observable when the source is absent."],"exampleFix":"// before\nvar obs = maybeNullCollection.GetWeakCollectionChangedObservable();\n\n// after\nvar obs = maybeNullCollection is null\n    ? Observable.Empty<NotifyCollectionChangedEventArgs>()\n    : maybeNullCollection.GetWeakCollectionChangedObservable();","handlingStrategy":"validation","validationCode":"if (collection is null) throw new ArgumentNullException(nameof(collection));\nvar obs = collection.GetWeakCollectionChangedObservable();","typeGuard":"static bool IsSubscribable(INotifyCollectionChanged? c) => c is not null;","tryCatchPattern":null,"preventionTips":["Initialize collection properties before subscribing.","Null-check the receiver before calling extension methods.","Return empty observables for absent sources rather than passing null."],"tags":["avalonia","collections","reactive","weak-subscription","null-argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}