dotnet/wpf · error · ArgumentException
ExtendedProperty is already part of the…
Error message
ExtendedProperty is already part of the ExtendedPropertyCollection.
What it means
ExtendedPropertyCollection.Add(Guid, object) first checks Contains(id) and throws ArgumentException(SR.EPExists, nameof(id)) — 'ExtendedProperty is already part of the ExtendedPropertyCollection.' — when a property with the same GUID already exists. The collection requires unique keys; duplicates must go through the indexer's set accessor instead.
Solutions
- Use the indexer (collection[guid] = value) to overwrite an existing property instead of Add.
- Check Contains(guid) before Add and skip, overwrite, or remove-then-add as appropriate.
- Deduplicate property lists before decoding/persisting ISF so the same id isn't added twice.
- Catch ArgumentException with the 'id' param name to handle duplicates from external data gracefully.
Example fix
// before
properties.Add(guid, value); // ArgumentException if guid already present
// after
if (properties.Contains(guid))
properties[guid] = value;
else
properties.Add(guid, value); Defensive patterns
Strategy: validation
Validate before calling
if (properties.Contains(id))
properties[id] = value;
else
properties.Add(id, value); Type guard
static bool IsNewProperty(ExtendedPropertyCollection c, Guid id) => !c.Contains(id);
Try / catch
try { properties.Add(id, value); }
catch (ArgumentException ex) when (ex.ParamName == "id") { properties[id] = value; /* upsert */ } Prevention
- Prefer the indexer for set-or-overwrite semantics
- Deduplicate ids when importing ISF
- Clear or diff collections before re-running imports
When it happens
Trigger: Calling Add(guid, value) twice with the same GUID; decoding ISF (DecodeRawISF) whose payload lists the same property id more than once for one object.
Common situations: Applying default properties on ink objects that already have them; replaying/importing ISF data with duplicated property tags (double-applied transforms or merges); re-running an import routine without clearing the collection.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Property not set.
- The GUID is not part of the ExtendedPropertyCollection.
- GUID cannot be empty.
- InvalidMatrixContainsInfinity
- InvalidMatrixContainsNaN
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/7f1972c368fb604c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/ExtendedPropertyCollection.cs:150
{
ExtendedPropertyCollection copied = new ExtendedPropertyCollection();
for (int x = 0; x < _extendedProperties.Count; x++)
{
copied.Add(_extendedProperties[x].Clone());
}
return copied;
}
/// <summary>
/// Add
/// </summary>
/// <param name="id">Id</param>
/// <param name="value">value</param>
internal void Add(Guid id, object value)
{
if (this.Contains(id))
{
throw new ArgumentException(SR.EPExists, nameof(id));
}
ExtendedProperty extendedProperty = new ExtendedProperty(id, value);
//this will raise change events
this.Add(extendedProperty);
}
/// <summary>
/// Remove
/// </summary>
/// <param name="id">id</param>
internal void Remove(Guid id)
{
if (!Contains(id))
{
throw new ArgumentException(SR.EPGuidNotFound, nameof(id));View on GitHub (pinned to 81131a70a4)