dotnet/wpf · error · ArgumentException
SR.Format(SR.PropertyAlreadyRegistered, Name…
Error message
SR.Format(SR.PropertyAlreadyRegistered, Name, ownerType.Name)
What it means
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.
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
Example fix
// before // OtherType already has: public static readonly DependencyProperty FooProperty = DependencyProperty.Register(nameof(Foo), ...) FooProperty.AddOwner(typeof(OtherType), new PropertyMetadata(0)); // throws: name taken // after FooProperty.AddOwner(typeof(NewOwnerType), new PropertyMetadata(0)); // type with no 'Foo' DP yet // or delete OtherType.FooProperty and let AddOwner provide it
Defensive patterns
Strategy: validation
Validate before calling
if (DependencyProperty.FromName(dp.Name, typeof(OtherType)) != null)
throw new InvalidOperationException($"{typeof(OtherType).Name} already has a DP named {dp.Name}");
dp.AddOwner(typeof(OtherType), meta); Try / catch
try { dp.AddOwner(typeof(OtherType), meta); }
catch (ArgumentException ex) { /* name collision: reuse the existing property instead */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- SR.Format(SR.PropertyAlreadyRegistered, name…
- SR.Format(SR.TypeMetadataAlreadyRegistered, forType.Name)
- Animation_CalculatedValueIsInvalidForProperty
- Animation_DependencyPropertyIsNotAnimatable
- InvalidOperationException()
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/7e4da138fa5316b7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyProperty.cs:757
/// <remarks>
/// The owner type is used when resolving a property by name (<see cref="FromName"/>)
/// </remarks>
/// <param name="ownerType">Additional owner type</param>
/// <param name="typeMetadata">Optional type metadata to override on owner's behalf</param>
/// <returns>This property</returns>
public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata)
{
ArgumentNullException.ThrowIfNull(ownerType);
// Map owner type to this property
// Build key
FromNameKey key = new(Name, ownerType);
lock (Synchronized)
{
if (PropertyFromName.ContainsKey(key))
{
throw new ArgumentException(SR.Format(SR.PropertyAlreadyRegistered, Name, ownerType.Name));
}
}
if (typeMetadata != null)
{
OverrideMetadata(ownerType, typeMetadata);
}
lock (Synchronized)
{
PropertyFromName[key] = this;
}
return this;
}
/// <summary>View on GitHub (pinned to 81131a70a4)