dotnet/wpf · error · ArgumentException
SR.InvalidGuid
Error message
SR.InvalidGuid
What it means
Annotation's constructor rejects Guid.Empty as an annotation id, throwing ArgumentException with SR.InvalidGuid. Every Annotation requires a unique, non-empty Guid identifier used for persistence and lookup. Guid.Empty is treated as an uninitialized/invalid id rather than a valid value.
Solutions
- Call Guid.NewGuid() to generate a fresh id for each new Annotation
- Validate ids are not Guid.Empty before constructing the Annotation
- If loading an existing annotation, ensure the persisted id was read correctly rather than defaulting
Example fix
// before
var ann = new Annotation(type, Guid.Empty, created, modified);
// after
Guid id = Guid.NewGuid();
if (id == Guid.Empty) throw new InvalidOperationException("id must be generated");
var ann = new Annotation(type, id, created, modified); Defensive patterns
Strategy: validation
Validate before calling
Guid id = Guid.NewGuid();
if (id == Guid.Empty) throw new InvalidOperationException("Annotation id must not be Guid.Empty");
var annotation = new Annotation(type, id, created, modified); Type guard
bool IsValidAnnotationId(Guid id) => id != Guid.Empty;
Prevention
- Never store Guid fields that can default to Guid.Empty for annotation ids; initialize with Guid.NewGuid()
- When reading ids from persistence, verify they parse to a non-empty Guid
- Add invariant checks in any factory method that wraps Annotation construction
When it happens
Trigger: Calling the public Annotation constructor (or the overload that accepts an id) passing Guid.Empty, typically because a Guid field was never initialized.
Common situations: Storing annotation ids in structs or fields that default to Guid.Empty; generating annotations before calling Guid.NewGuid(); reading ids from data sources that return zeroed Guids.
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
- SR.InvalidGuid
- anchorLocator.Parts
- annotation component
- Drawing Attribute tag embedded in ISF stream does not match…
- Global Custom Attribute tag embedded in ISF stream does not…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d668a0767c248cca.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs:136
/// <exception cref="ArgumentNullException">annotationType is null</exception>
/// <exception cref="ArgumentException">lastModificationTime is earlier than creationTime</exception>
/// <exception cref="ArgumentException">annotationType's Name or Namespace is null or empty string</exception>
/// <exception cref="ArgumentException">id is equal to Guid.Empty</exception>
public Annotation(XmlQualifiedName annotationType, Guid id, DateTime creationTime, DateTime lastModificationTime)
{
ArgumentNullException.ThrowIfNull(annotationType);
if (String.IsNullOrEmpty(annotationType.Name))
{
throw new ArgumentException(SR.TypeNameMustBeSpecified, "annotationType.Name");//needs better message
}
if (String.IsNullOrEmpty(annotationType.Namespace))
{
throw new ArgumentException(SR.TypeNameMustBeSpecified, "annotationType.Namespace");//needs better message
}
if (id.Equals(Guid.Empty))
{
throw new ArgumentException(SR.InvalidGuid, nameof(id));
}
if (lastModificationTime.CompareTo(creationTime) < 0)
{
throw new ArgumentException(SR.ModificationEarlierThanCreation, nameof(lastModificationTime));
}
_id = id;
_typeName = annotationType;
_created = creationTime;
_modified = lastModificationTime;
Init();
}
#endregion Constructors
//------------------------------------------------------
//View on GitHub (pinned to 81131a70a4)