{"record":{"id":"aee69078160045fe","repo":"AvaloniaUI/Avalonia","slug":"value-cannot-be-null-parameter-observer-aee690","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'observer')","messagePattern":"Value cannot be null\\. \\(Parameter 'observer'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Reactive/SingleSubscriberObservableBase.cs","lineNumber":14,"sourceCode":"﻿using System;\nusing Avalonia.Threading;\n\nnamespace Avalonia.Reactive\n{\n    internal abstract class SingleSubscriberObservableBase<T> : IObservable<T>, IDisposable\n    {\n        private Exception? _error;\n        private IObserver<T>? _observer;\n        private bool _completed;\n\n        public IDisposable Subscribe(IObserver<T> observer)\n        {\n            _ = observer ?? throw new ArgumentNullException(nameof(observer));\n            Dispatcher.UIThread.VerifyAccess();\n\n            if (_observer != null)\n            {\n                throw new InvalidOperationException(\"The observable can only be subscribed once.\");\n            }\n\n            if (_error != null)\n            {\n                observer.OnError(_error);\n            }\n            else if (_completed)\n            {\n                observer.OnCompleted();\n            }\n            else\n            {\n                _observer = observer;","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Reactive/SingleSubscriberObservableBase.cs#L1-L32","documentation":"Thrown by SingleSubscriberObservableBase<T>.Subscribe when the IObserver<T> argument is null. This internal base supports observables that can have exactly one active subscriber (e.g. a single UI-thread property source). It also requires UI-thread access, so the null check happens before the threading check.","triggerScenarios":"Calling a single-subscriber observable's Subscribe(null), or passing an observer reference that is null. Reached internally from Avalonia property/binding code that forgot to construct an observer.","commonSituations":"A binding adapter passes null when the target is detached but still subscribed; an observer field is read before assignment in a race; refactor left a null observer in a subscription chain.","solutions":["Pass a real observer instance or use a Subscribe lambda overload.","Null-check before subscribing and skip the call.","Ensure the observer is constructed before the subscription is initiated."],"exampleFix":"// before\nsingleSubObs.Subscribe(myObserver); // myObserver is null\n// after\nif (myObserver != null) singleSubObs.Subscribe(myObserver);","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));\nsource.Subscribe(observer);","typeGuard":"static bool IsValidObserver<T>(IObserver<T>? o) => o is not null;","tryCatchPattern":null,"preventionTips":["Subscribe on the UI thread with a real observer (the base also calls Dispatcher.UIThread.VerifyAccess).","Do not reuse a null observer reference from a detached binding.","Construct the observer at the subscription site."],"tags":["reactive","null-argument","observer","single-subscriber","ui-thread"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}