{"record":{"id":"dc205b2c6574f72c","repo":"AvaloniaUI/Avalonia","slug":"value-cannot-be-null-parameter-disposables","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'disposables')","messagePattern":"Value cannot be null\\. \\(Parameter 'disposables'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Reactive/CompositeDisposable.cs","lineNumber":41,"sourceCode":"        if (capacity < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(capacity));\n        }\n\n        _disposables = new List<IDisposable?>(capacity);\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"CompositeDisposable\"/> class from a group of disposables.\n    /// </summary>\n    /// <param name=\"disposables\">Disposables that will be disposed together.</param>\n    /// <exception cref=\"ArgumentNullException\"><paramref name=\"disposables\"/> is <c>null</c>.</exception>\n    /// <exception cref=\"ArgumentException\">Any of the disposables in the <paramref name=\"disposables\"/> collection is <c>null</c>.</exception>\n    public CompositeDisposable(params IDisposable[] disposables)\n    {\n        if (disposables == null)\n        {\n            throw new ArgumentNullException(nameof(disposables));\n        }\n\n        _disposables = ToList(disposables);\n\n        // _count can be read by other threads and thus should be properly visible\n        // also releases the _disposables contents so it becomes thread-safe\n        Volatile.Write(ref _count, _disposables.Count);\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"CompositeDisposable\"/> class from a group of disposables.\n    /// </summary>\n    /// <param name=\"disposables\">Disposables that will be disposed together.</param>\n    /// <exception cref=\"ArgumentNullException\"><paramref name=\"disposables\"/> is <c>null</c>.</exception>\n    /// <exception cref=\"ArgumentException\">Any of the disposables in the <paramref name=\"disposables\"/> collection is <c>null</c>.</exception>\n    public CompositeDisposable(IList<IDisposable> disposables)\n    {\n        if (disposables == null)","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Reactive/CompositeDisposable.cs#L23-L59","documentation":"CompositeDisposable(params IDisposable[] disposables) throws ArgumentNullException(nameof(disposables)) when the array is null, before copying it. Because it is a params array, a literal null (not an array of nulls) is the trigger; this guards against passing null as the single argument.","triggerScenarios":"Calling new CompositeDisposable((IDisposable[])null) or new CompositeDisposable(null) where overload resolution selects the params overload, or passing a null IDisposable[] variable.","commonSituations":"A collected array of disposables that ended up null because the source LINQ query returned null or was never initialized, then spread into the params constructor.","solutions":["Pass an actual array (possibly empty) instead of null: new CompositeDisposable(disposables ?? Array.Empty<IDisposable>()).","Initialize disposable collections to empty rather than null.","Use the IList overload or Add individually when the collection may be empty."],"exampleFix":"// before\nvar cd = new CompositeDisposable(maybeNullArray);\n\n// after\nvar cd = new CompositeDisposable(maybeNullArray ?? Array.Empty<IDisposable>());","handlingStrategy":"validation","validationCode":"var arr = maybeNullArray ?? Array.Empty<IDisposable>();\nvar cd = new CompositeDisposable(arr);","typeGuard":"bool NotNull(IDisposable[]? a) => a is not null;","tryCatchPattern":null,"preventionTips":["Coalesce null arrays to Array.Empty<IDisposable>().","Initialize disposable arrays eagerly.","Prefer the IList overload or individual Add when emptiness is possible."],"tags":["avalonia","reactive","disposables","argumentnull","params-array"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}