{"record":{"id":"7e4da138fa5316b7","repo":"dotnet/wpf","slug":"sr-format-sr-propertyalreadyregistered-name-ownertype-name-7e4da1","errorCode":null,"errorMessage":"SR.Format(SR.PropertyAlreadyRegistered, Name, ownerType.Name)","messagePattern":"SR\\.Format\\(SR\\.PropertyAlreadyRegistered, Name, ownerType\\.Name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs","lineNumber":757,"sourceCode":"        /// <remarks>\n        ///     The owner type is used when resolving a property by name (<see cref=\"FromName\"/>)\n        /// </remarks>\n        /// <param name=\"ownerType\">Additional owner type</param>\n        /// <param name=\"typeMetadata\">Optional type metadata to override on owner's behalf</param>\n        /// <returns>This property</returns>\n        public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata)\n        {\n            ArgumentNullException.ThrowIfNull(ownerType);\n\n            // Map owner type to this property\n            // Build key\n            FromNameKey key = new(Name, ownerType);\n\n            lock (Synchronized)\n            {\n                if (PropertyFromName.ContainsKey(key))\n                {\n                    throw new ArgumentException(SR.Format(SR.PropertyAlreadyRegistered, Name, ownerType.Name));\n                }\n            }\n\n            if (typeMetadata != null)\n            {\n                OverrideMetadata(ownerType, typeMetadata);\n            }\n\n            lock (Synchronized)\n            {\n                PropertyFromName[key] = this;\n            }\n\n            return this;\n        }\n\n\n        /// <summary>","sourceCodeStart":739,"sourceCodeEnd":775,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs#L739-L775","documentation":"AddOwner throws this ArgumentException when a property with the same Name is already registered for the given ownerType (PropertyFromName already contains the (Name, ownerType) key). Each dependency property name must be unique per owner type, including names added via AddOwner.","triggerScenarios":"Calling dp.AddOwner(otherType) (or dp.AddOwner(otherType, metadata)) where otherType already has a property named Name registered — typically because otherType declared its own DP with the same name via DependencyProperty.Register.","commonSituations":"Adding an owner to reuse a property on a type that independently declared a same-named DP; renaming refactors that collide with inherited owners; two assemblies both claiming the same name on a shared type.","solutions":["Remove the AddOwner call and use the type's existing same-named property instead of adding a duplicate owner","Rename your property (and its Register call) so the (name, ownerType) pair is unique","If you own the other type, delete its duplicate DP declaration and rely on the added-owner property"],"exampleFix":"// before\n// OtherType already has: public static readonly DependencyProperty FooProperty = DependencyProperty.Register(nameof(Foo), ...)\nFooProperty.AddOwner(typeof(OtherType), new PropertyMetadata(0)); // throws: name taken\n// after\nFooProperty.AddOwner(typeof(NewOwnerType), new PropertyMetadata(0)); // type with no 'Foo' DP yet\n// or delete OtherType.FooProperty and let AddOwner provide it","handlingStrategy":"validation","validationCode":"if (DependencyProperty.FromName(dp.Name, typeof(OtherType)) != null)\n    throw new InvalidOperationException($\"{typeof(OtherType).Name} already has a DP named {dp.Name}\");\ndp.AddOwner(typeof(OtherType), meta);","typeGuard":null,"tryCatchPattern":"try { dp.AddOwner(typeof(OtherType), meta); }\ncatch (ArgumentException ex) { /* name collision: reuse the existing property instead */ }","preventionTips":["Before AddOwner, check the target type doesn't already declare a same-named DP","Establish naming conventions (owner-prefixed names) for shared/attached DPs","Prefer reusing the existing property over adding a duplicate owner"],"tags":["wpf","dependency-property","addowner","duplicate-registration","name-collision"],"backgroundTag":"file-already-exists","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}