dotnet/wpf · error · ArgumentException

SR.InvalidGuid

Error message

SR.InvalidGuid

What it means

The AnnotationResource(Guid) constructor throws ArgumentException when the id parameter equals Guid.Empty. Every annotation resource must have a unique non-empty identifier; Guid.Empty is not a valid resource id per the annotations schema. The parameterless constructor generates a new Guid, so this only fires when a caller explicitly supplies an empty Guid.

Solutions

  1. Use the parameterless AnnotationResource() constructor to auto-generate a valid Guid.
  2. Generate a new id with Guid.NewGuid() before constructing the resource.
  3. Ensure the Guid variable being passed is actually initialized; fix default(Guid) usage in your data model.
  4. Validate ids after deserialization and regenerate empty ones.

Example fix

// before
var resource = new AnnotationResource(Guid.Empty);

// after
var resource = new AnnotationResource(Guid.NewGuid());
Defensive patterns

Strategy: validation

Validate before calling

if (id == Guid.Empty)
    id = Guid.NewGuid();
var resource = new AnnotationResource(id);

Type guard

bool IsValidResourceId(Guid id) => id != Guid.Empty;

Try / catch

try { resource = new AnnotationResource(id); }
catch (ArgumentException) { resource = new AnnotationResource(Guid.NewGuid()); }

Prevention

When it happens

Trigger: Constructing AnnotationResource with Guid.Empty, e.g. new AnnotationResource(Guid.Empty), often because a Guid field was default-initialized and never assigned.

Common situations: Deserializing metadata where the id was lost and default(Guid) was used; creating resources from data structures where Guid fields default to Guid.Empty; typo of passing an unset variable instead of a newly generated Guid.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/ba2a9e7feeae5abf. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs:76

        {
            ArgumentNullException.ThrowIfNull(name);

            _name = name;
            _id = Guid.NewGuid();
        }

        /// <summary>
        ///     Creates an instance of Resource with the specified Guid as its Id.
        ///     This constructor is for store implementations that use their own
        ///     method of serialization and need a way to create a Resource with
        ///     the correct read-only data.
        /// </summary>
        /// <param name="id">the new Resource's id</param>
        /// <exception cref="ArgumentException">id is equal to Guid.Empty</exception>
        public AnnotationResource(Guid id)
        {
            if (Guid.Empty.Equals(id))
                throw new ArgumentException(SR.InvalidGuid, nameof(id));

            // Guid is a struct and cannot be null
            _id = id;
        }

        #endregion Constructors

        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods
        
        #region IXmlSerializable Implementation

        /// <summary>

View on GitHub (pinned to 81131a70a4)