{"record":{"id":"21e0cde42065dd21","repo":"dotnet/wpf","slug":"sr-unexpectedxmltag-template-unexpectedxmltag-arg-reader","errorCode":null,"errorMessage":"SR.UnexpectedXmlTag (template: UnexpectedXmlTag, arg: reader.LocalName)","messagePattern":"SR\\.UnexpectedXmlTag \\(template: UnexpectedXmlTag, arg: reader\\.LocalName\\)","errorType":"exception","errorClass":"System.Xml.XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlSignatureManifest.cs","lineNumber":455,"sourceCode":"                    else if ((string.Equals(reader.LocalName, XTable.Get(XTable.ID.RelationshipsGroupReferenceTagName), StringComparison.Ordinal)))\n                    {\n                        // RelationshipsGroupReference tags must be empty with a single SourceType attribute\n                        string type = reader.GetAttribute(XTable.Get(XTable.ID.SourceTypeAttrName));\n                        if (type != null && type.Length > 0)\n                        {\n                            // lazy init\n                            if (relationshipSelectors == null)\n                                relationshipSelectors = new List<PackageRelationshipSelector>();\n\n                            // got a legal SourceType attribute\n                            relationshipSelectors.Add(new PackageRelationshipSelector(owningPartUri, PackageRelationshipSelectorType.Type, type));\n                            continue;\n                        }\n                    }\n                }\n\n                // if we get to here, we have not found a legal tag so we throw\n                throw new XmlException(SR.Format(SR.UnexpectedXmlTag, reader.LocalName));\n            }\n        }\n\n        /// <summary>\n        /// Generate Manifest tag\n        /// </summary>\n        /// <param name=\"manager\">manager</param>\n        /// <param name=\"xDoc\">current Xml doc</param>\n        /// <param name=\"hashAlgorithm\">hash algorithm to hash with</param>\n        /// <param name=\"parts\">parts to sign - possibly null</param>\n        /// <param name=\"relationshipSelectors\">relationshipSelectors that represent the\n        /// relationships that have to be signed - possibly null</param>\n        /// <returns></returns>\n        internal static XmlNode GenerateManifest(\n            PackageDigitalSignatureManager manager,\n            XmlDocument xDoc,\n            HashAlgorithm hashAlgorithm,\n            IEnumerable<Uri> parts,","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlSignatureManifest.cs#L437-L473","documentation":"ParseRelationshipsTransform parses the <Transform> XML of a relationships transform inside a package digital signature and throws UnexpectedXmlTag when it encounters an element name that is not a legal tag for this transform grammar. The library requires the XML to strictly follow the OPC/W3C XML-DSig relationships-transform schema; any unexpected element means the signature stream is malformed or hand-edited.","triggerScenarios":"Calling XmlSignatureManifest.ParseRelationshipsTransform (via ParseTransformsTag) on a <Transform> element whose inner XML contains a tag other than the ones the parser accepts (e.g. an unknown element instead of the expected RelationshipsDocument/element structure).","commonSituations":"Packages whose .signature XML was edited by hand or produced by a non-OPC-compliant signing tool; corrupted or truncated signature parts; tools writing extra extension elements inside the transform.","solutions":["Inspect the signed XML at the reported location and remove/rename the element that is not part of the relationships-transform schema","Re-sign the package with a compliant tool so the transform XML is regenerated correctly","Restore the package from a known-good copy if the signature part is corrupted","If you control the producer, verify it only emits tags allowed by ParseRelationshipsTransform"],"exampleFix":"// before (hand-edited transform)\n<Transform Algorithm=\"...relationships#transform\"><MyExtension/></Transform>\n// after (schema-conformant)\n<Transform Algorithm=\"http://schemas.openxmlformats.org/package/2006/relationships#transform\"/>","handlingStrategy":"validation","validationCode":"// Before trusting a package signature, sanity-check transform XML\nbool LooksConformant(string transformXml)\n{\n    var doc = XDocument.Parse(transformXml);\n    var allowed = new HashSet<string>(StringComparer.Ordinal) { \"Relationships\", \"Transform\" };\n    return doc.Descendants().All(e => allowed.Contains(e.Name.LocalName));\n}","typeGuard":null,"tryCatchPattern":"try { ValidatePackageSignatures(package); }\ncatch (XmlException ex) when (ex.Message.Contains(\"tag\")) { /* treat signature as invalid/untrusted */ }","preventionTips":["Never hand-edit .signature XML parts","Sign only with OPC-compliant signing tools","Run schema validation on signature parts before distribution"],"tags":["xml","digital-signature","packaging"],"backgroundTag":"schema-validation-failed","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"}