{"record":{"id":"b37fd6571ac65acc","repo":"dotnet/wpf","slug":"sr-unsupportedhashalgorithm-xmlsignaturemanifest","errorCode":null,"errorMessage":"SR.UnsupportedHashAlgorithm","messagePattern":"SR\\.UnsupportedHashAlgorithm","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlSignatureManifest.cs","lineNumber":169,"sourceCode":"        /// </summary>\n        /// <param name=\"reader\"></param>\n        private static string ParseDigestAlgorithmTag(XmlReader reader)\n        {\n            // verify namespace and lack of attributes\n            if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) > 1\n                || !string.Equals(reader.NamespaceURI, SignedXml.XmlDsigNamespaceUrl, StringComparison.Ordinal)\n                || reader.Depth != 3)\n                throw new XmlException(SR.XmlSignatureParseError);\n\n            // get the Algorithm attribute\n            string hashAlgorithm = null;\n            if (reader.HasAttributes)\n            {\n                hashAlgorithm = reader.GetAttribute(XTable.Get(XTable.ID.AlgorithmAttrName));\n            }\n\n            if (hashAlgorithm == null || hashAlgorithm.Length == 0)\n                throw new XmlException(SR.UnsupportedHashAlgorithm);\n\n            return hashAlgorithm;\n        }\n\n        /// <summary>\n        /// Parse the DigestValue tag\n        /// </summary>\n        /// <param name=\"reader\"></param>\n        private static string ParseDigestValueTag(XmlReader reader)\n        {\n            Debug.Assert(reader != null);\n\n            // verify namespace and lack of attributes\n            if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) > 0\n                || !string.Equals(reader.NamespaceURI, SignedXml.XmlDsigNamespaceUrl, StringComparison.Ordinal)\n                || reader.Depth != 3)\n                throw new XmlException(SR.XmlSignatureParseError);\n","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlSignatureManifest.cs#L151-L187","documentation":"System.IO.Packaging throws this XmlException when the <DigestMethod> element inside a signature <Reference> has no Algorithm attribute, or the attribute is an empty string. The hash algorithm URI is mandatory for XMLDSig digest verification, so the parser cannot proceed.","triggerScenarios":"ParseReference -> ParseDigestAlgorithmTag reads the Algorithm attribute via XTable and finds hashAlgorithm null or zero-length, then throws.","commonSituations":"Hand-authored or tool-stripped signature XML where Algorithm was dropped; XML normalization pipelines that removed 'redundant' attributes; corrupted package parts truncated mid-element.","solutions":["Add the Algorithm attribute with a valid digest URI, e.g. Algorithm=\"http://www.w3.org/2001/04/xmlenc#sha256\"","Re-sign the package with PackageDigitalSignatureManager.Sign to regenerate well-formed signature XML","Restore the package from an uncorrupted copy if the signature part was damaged in transit/storage"],"exampleFix":"// before\n// <DigestMethod/>\n// after\n// <DigestMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#sha256\"/>","handlingStrategy":"validation","validationCode":"var doc = XDocument.Load(signaturePartStream);\nXNamespace ds = \"http://www.w3.org/2000/09/xmldsig#\";\nforeach (var dm in doc.Descendants(ds + \"DigestMethod\"))\n{\n    var alg = (string)dm.Attribute(\"Algorithm\");\n    if (string.IsNullOrEmpty(alg)) throw new InvalidDataException(\"DigestMethod missing Algorithm attribute\");\n}","typeGuard":null,"tryCatchPattern":"try { VerifyPackageSignature(package); }\ncatch (XmlException ex) when (ex.Message.Contains(\"UnsupportedHashAlgorithm\"))\n{\n    // the signature lacks a digest algorithm URI; re-sign required\n}","preventionTips":["Always emit Algorithm on DigestMethod when generating signature XML","Do not strip 'seemingly redundant' attributes during XML normalization","Verify signature parts survive storage/transfer intact"],"tags":["xml","digital-signature","packaging","wpf","missing-attribute"],"backgroundTag":"missing-required-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}