dotnet/wpf · error · System.Xml.XmlException
SR.UnexpectedXmlTag (template: UnexpectedXmlTag, arg…
Error message
SR.UnexpectedXmlTag (template: UnexpectedXmlTag, arg: reader.LocalName)
What it means
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.
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
Example fix
// before (hand-edited transform) <Transform Algorithm="...relationships#transform"><MyExtension/></Transform> // after (schema-conformant) <Transform Algorithm="http://schemas.openxmlformats.org/package/2006/relationships#transform"/>
Defensive patterns
Strategy: validation
Validate before calling
// Before trusting a package signature, sanity-check transform XML
bool LooksConformant(string transformXml)
{
var doc = XDocument.Parse(transformXml);
var allowed = new HashSet<string>(StringComparer.Ordinal) { "Relationships", "Transform" };
return doc.Descendants().All(e => allowed.Contains(e.Name.LocalName));
} Try / catch
try { ValidatePackageSignatures(package); }
catch (XmlException ex) when (ex.Message.Contains("tag")) { /* treat signature as invalid/untrusted */ } Prevention
- Never hand-edit .signature XML parts
- Sign only with OPC-compliant signing tools
- Run schema validation on signature parts before distribution
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- SR.PackageSignatureCorruption
- SR.PartReferenceUriMalformed
- SR.RequiredTagNotFound (template: RequiredTagNotFound, arg…
- SR.UnsupportedHashAlgorithm
- SR.XmlSignatureParseError
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/21e0cde42065dd21.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlSignatureManifest.cs:455
else if ((string.Equals(reader.LocalName, XTable.Get(XTable.ID.RelationshipsGroupReferenceTagName), StringComparison.Ordinal)))
{
// RelationshipsGroupReference tags must be empty with a single SourceType attribute
string type = reader.GetAttribute(XTable.Get(XTable.ID.SourceTypeAttrName));
if (type != null && type.Length > 0)
{
// lazy init
if (relationshipSelectors == null)
relationshipSelectors = new List<PackageRelationshipSelector>();
// got a legal SourceType attribute
relationshipSelectors.Add(new PackageRelationshipSelector(owningPartUri, PackageRelationshipSelectorType.Type, type));
continue;
}
}
}
// if we get to here, we have not found a legal tag so we throw
throw new XmlException(SR.Format(SR.UnexpectedXmlTag, reader.LocalName));
}
}
/// <summary>
/// Generate Manifest tag
/// </summary>
/// <param name="manager">manager</param>
/// <param name="xDoc">current Xml doc</param>
/// <param name="hashAlgorithm">hash algorithm to hash with</param>
/// <param name="parts">parts to sign - possibly null</param>
/// <param name="relationshipSelectors">relationshipSelectors that represent the
/// relationships that have to be signed - possibly null</param>
/// <returns></returns>
internal static XmlNode GenerateManifest(
PackageDigitalSignatureManager manager,
XmlDocument xDoc,
HashAlgorithm hashAlgorithm,
IEnumerable<Uri> parts,View on GitHub (pinned to 81131a70a4)