{"record":{"id":"b23d5effbe6d0e58","repo":"AvaloniaUI/Avalonia","slug":"the-member-accessor-was-not-subscribed","errorCode":null,"errorMessage":"The member accessor was not subscribed.","messagePattern":"The member accessor was not subscribed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/Core/Plugins/PropertyAccessorBase.cs","lineNumber":49,"sourceCode":"        public void Subscribe(Action<object?> listener)\n        {\n            _ = listener ?? throw new ArgumentNullException(nameof(listener));\n\n            if (_listener != null)\n            {\n                throw new InvalidOperationException(\n                    \"A member accessor can be subscribed to only once.\");\n            }\n\n            _listener = listener;\n            SubscribeCore();\n        }\n\n        public void Unsubscribe()\n        {\n            if (_listener == null)\n            {\n                throw new InvalidOperationException(\n                    \"The member accessor was not subscribed.\");\n            }\n\n            UnsubscribeCore();\n            _listener = null;\n        }\n\n        /// <summary>\n        /// Publishes a value to the listener.\n        /// </summary>\n        /// <param name=\"value\">The value.</param>\n        protected void PublishValue(object? value) => _listener?.Invoke(value);\n\n        /// <summary>\n        /// When overridden in a derived class, begins listening to the member.\n        /// </summary>\n        protected abstract void SubscribeCore();\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/Core/Plugins/PropertyAccessorBase.cs#L31-L67","documentation":"PropertyAccessorBase.Unsubscribe throws InvalidOperationException when _listener is null, i.e. Unsubscribe was called on an accessor that was never subscribed (or already unsubscribed). The contract is Subscribe-then-Unsubscribe. (Note: Dispose is safe to call when not subscribed, since it guards on _listener != null.)","triggerScenarios":"Calling accessor.Unsubscribe() before any Subscribe; calling Unsubscribe twice; manual cleanup ordering bugs that double-unsubscribe.","commonSituations":"Direct Unsubscribe calls without a prior Subscribe; re-entrant dispose logic; cleanup paths that assume subscription state incorrectly.","solutions":["Ensure Subscribe was called before Unsubscribe.","Guard cleanup with a subscription flag: if (_subscribed) accessor.Unsubscribe().","Prefer Dispose over manual Unsubscribe — Dispose is a no-op when not subscribed."],"exampleFix":"// before\naccessor.Unsubscribe(); // throws if not subscribed\n// after\nif (_subscribed)\n{\n    accessor.Unsubscribe();\n    _subscribed = false;\n}","handlingStrategy":"validation","validationCode":"// Guard Unsubscribe with the known subscription state:\nif (_subscribed) { accessor.Unsubscribe(); _subscribed = false; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always Subscribe before Unsubscribe.","Track subscription state with a flag to avoid double-unsubscribe.","Prefer Dispose over manual Unsubscribe — Dispose is safe when not subscribed."],"tags":["binding","accessor","subscription","lifecycle"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}