{"record":{"id":"57242a4a48178c27","repo":"dotnet/wpf","slug":"0-id-is-not-a-valid-xsd-id","errorCode":null,"errorMessage":"'{0}' ID is not a valid XSD ID.","messagePattern":"'(.+?)' ID is not a valid XSD ID\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs","lineNumber":980,"sourceCode":"                    //if (ids.Contains(obj.Id))\n                    if (ids.Exists(new StringMatchPredicate(obj.Id).Match))\n                        throw new ArgumentException(SR.SignatureObjectIdMustBeUnique, nameof(signatureObjects));\n                    else\n                        ids.Add(obj.Id);\n                }\n            }\n\n            // ensure id is legal Xml id\n            if (!string.IsNullOrEmpty(signatureId))\n            {\n                try\n                {\n                    // An XSD ID is an NCName that is unique.\n                    System.Xml.XmlConvert.VerifyNCName(signatureId);\n                }\n                catch (System.Xml.XmlException xmlException)\n                {\n                    throw new ArgumentException(SR.Format(SR.NotAValidXmlIdString, signatureId), nameof(signatureId), xmlException);\n                }\n            }\n        }\n\n        /// <summary>\n        /// Returns true if the given enumerator is null or empty\n        /// </summary>\n        /// <param name=\"enumerable\">may be null</param>\n        /// <returns>true if enumerator is empty or null</returns>\n        private bool EnumeratorEmptyCheck(System.Collections.IEnumerable enumerable)\n        {\n            if (enumerable == null)\n                return true;            // null means empty\n\n            // see if it's really a collection as this is more efficient than enumerating\n            if (enumerable is System.Collections.ICollection collection)\n            {\n                return (collection.Count == 0);","sourceCodeStart":962,"sourceCodeEnd":998,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs#L962-L998","documentation":"VerifySignArguments validates the signatureId argument by calling XmlConvert.VerifyNCName, since an XSD ID must be a valid NCName; if the value fails, it throws ArgumentException (SR.NotAValidXmlIdString, formatted with the offending id) wrapping the original XmlException. The signature's Id XML attribute must be a legal XSD ID.","triggerScenarios":"Calling Sign() overload that takes an id (via signatureObjects/objectReferences or the id parameter) with a string that is not an NCName — e.g. contains spaces, starts with a digit, is empty, or contains ':' or other invalid characters.","commonSituations":"Passing a GUID-like string that starts with a digit, using a display name with spaces as the signature id, or localizing/serializing ids with invalid characters.","solutions":["Use an NCName-safe id: start with a letter or underscore and use only letters, digits, '.', '-', '_' (e.g. '_sig1' or 'Signature1').","Prefix numeric ids with an underscore: '_' + Guid.NewGuid().ToString(\"N\").","Pre-validate with XmlConvert.VerifyNCName(id) before calling Sign to fail early with your own message."],"exampleFix":"// before\nmgr.Sign(cert, parts, \"123 my signature\"); // ArgumentException: not a valid XSD ID\n// after\nstring sigId = \"_\" + Guid.NewGuid().ToString(\"N\"); // valid NCName\nXmlConvert.VerifyNCName(sigId);\nmgr.Sign(cert, parts, sigId);","handlingStrategy":"validation","validationCode":"try { XmlConvert.VerifyNCName(signatureId); }\ncatch (XmlException) { throw new InvalidOperationException($\"'{signatureId}' is not a valid NCName/XSD ID.\"); }","typeGuard":"bool IsValidXsdId(string s) => !string.IsNullOrEmpty(s) && (char.IsLetter(s[0]) || s[0] == '_') && s.All(c => char.IsLetterOrDigit(c) || c == '.' || c == '-' || c == '_' || c == ':');","tryCatchPattern":"try { mgr.Sign(cert, parts, sigId); }\ncatch (ArgumentException ex) when (ex.ParamName == \"signatureId\") { /* use an NCName-safe id */ }","preventionTips":["Start ids with a letter or underscore, never a digit.","Only use letters, digits, '.', '-', '_' in ids; no spaces.","Wrap GUIDs: '_' + guid.ToString(\"N\")."],"tags":["wpf","packaging","argument","xml-id","xsd","digital-signature"],"backgroundTag":"invalid-identifier-format","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"}