{"record":{"id":"661887cca3552883","repo":"PrismLibrary/Prism","slug":"propertyexpression-is-already-being-observed","errorCode":null,"errorMessage":"{propertyExpression} is already being observed.","messagePattern":"(.+?) is already being observed\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Commands/DelegateCommandBase.cs","lineNumber":100,"sourceCode":"        protected abstract void Execute(object? parameter);\n\n        /// <summary>\n        /// Handle the internal invocation of <see cref=\"ICommand.CanExecute(object)\"/>\n        /// </summary>\n        /// <param name=\"parameter\"></param>\n        /// <returns><see langword=\"true\"/> if the Command Can Execute, otherwise <see langword=\"false\" /></returns>\n        protected abstract bool CanExecute(object? parameter);\n\n        /// <summary>\n        /// Observes a property that implements INotifyPropertyChanged, and automatically calls DelegateCommandBase.RaiseCanExecuteChanged on property changed notifications.\n        /// </summary>\n        /// <typeparam name=\"T\">The object type containing the property specified in the expression.</typeparam>\n        /// <param name=\"propertyExpression\">The property expression. Example: ObservesProperty(() => PropertyName).</param>\n        protected internal void ObservesPropertyInternal<T>(Expression<Func<T>> propertyExpression)\n        {\n            if (_observedPropertiesExpressions.Contains(propertyExpression.ToString()))\n            {\n                throw new ArgumentException($\"{propertyExpression} is already being observed.\",\n                    nameof(propertyExpression));\n            }\n            else\n            {\n                _observedPropertiesExpressions.Add(propertyExpression.ToString());\n                PropertyObserver.Observes(propertyExpression, RaiseCanExecuteChanged);\n            }\n        }\n\n        #region IsActive\n\n        /// <summary>\n        /// Gets or sets a value indicating whether the object is active.\n        /// </summary>\n        /// <value><see langword=\"true\" /> if the object is active; otherwise <see langword=\"false\" />.</value>\n        public bool IsActive\n        {\n            get => _isActive;","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Commands/DelegateCommandBase.cs#L82-L118","documentation":"DelegateCommandBase.ObservesPropertyInternal throws ArgumentException when the same property expression is observed more than once on the command. This prevents duplicate subscriptions to RaiseCanExecuteChanged for the same property.","triggerScenarios":"Calling ObservesProperty(()=>Foo) (or using ObservesProperty in the constructor helpers) twice with an equivalent expression for the same property on the same command instance.","commonSituations":"Copy-pasted fluent constructor chains that include the same property twice; subclass constructors calling base with ObservesProperty and then calling ObservesProperty again for the same property.","solutions":["Remove the duplicate ObservesProperty call so each property is observed once.","Combine into a single call site (e.g. only in the base constructor chain).","Track already-observed properties if construction is dynamic."],"exampleFix":"// before\nSaveCommand = new DelegateCommand(Save, () => CanSave)\n    .ObservesProperty(() => CanSave)\n    .ObservesProperty(() => CanSave); // duplicate\n// after\nSaveCommand = new DelegateCommand(Save, () => CanSave)\n    .ObservesProperty(() => CanSave);","handlingStrategy":"validation","validationCode":"var expr = nameof(CanSave);\n// ensure ObservesProperty(() => CanSave) appears only once in the fluent chain","typeGuard":null,"tryCatchPattern":"try { cmd.ObservesProperty(() => CanSave); }\ncatch (ArgumentException ex) { logger.LogWarning(ex, \"property already observed\"); }","preventionTips":["Keep ObservesProperty calls in one place (base constructor chain).","Search the fluent chain for duplicate property expressions before adding new ones.","Document which properties a command observes to avoid duplicates in subclasses."],"tags":["csharp","commands","duplicate-registration","expression"],"backgroundTag":"unsupported-operation","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}