dotnet/wpf · error · System.Xml.XmlException
SR.PartReferenceUriMalformed
Error message
SR.PartReferenceUriMalformed
What it means
ParsePartUriAttribute parses the SourceUri/ContentType attributes of a <Reference> in a signed manifest. If PackUriHelper.ValidatePartUri rejects the URI (or the derived content type is invalid), the code rethrows PartReferenceUriMalformed as an XmlException because the signature XML references a malformed part URI — meaning the signature is corrupt or non-conformant.
Solutions
- Fix the producing tool to write valid OPC part URIs (PackUriHelper-compliant relative part names)
- Validate part URIs with PackUriHelper.ValidatePartUri before writing them into signatures
- Re-sign or regenerate the package from source since validation cannot proceed on a malformed reference
- Treat the package signature as invalid and fall back to untrusted handling if you don't control the source
Example fix
// before (written into signature) <Reference SourceUri="http://example.com/doc.xml" .../> // after (valid relative OPC part URI) <Reference SourceUri="/doc.xml" ContentType="application/xml" .../>
Defensive patterns
Strategy: try-catch
Validate before calling
bool IsValidPartUri(string s) =>
Uri.TryCreate(s, UriKind.Relative, out var u) &&
TryGet(() => PackUriHelper.ValidatePartUri(u)) != null;
static T TryGet<T>(Func<T> f) { try { return f(); } catch { return default; } } Try / catch
try { package.VerifySignatures(); }
catch (XmlException ex) when (ex.Message.Contains("malformed") || ex.Message.Contains("PartReference")) { /* mark package signature invalid */ } Prevention
- Use PackUriHelper.CreatePartUri/ValidatePartUri when generating part names
- Never write absolute URIs into signature references
- Round-trip test signatures produced by your signing tool
When it happens
Trigger: Signature validation (via ParsePartUri -> ParsePartUriAttribute) encountering a <Reference> whose URI substring fails PackUriHelper.ValidatePartUri — e.g. illegal characters, absolute URIs where relative required, or invalid part name syntax.
Common situations: Packages signed by third-party tools writing non-canonical part names; signature XML edited or corrupted in transit; part names with characters needing escaping that weren't.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- SR.PackageSignatureCorruption
- SR.RequiredTagNotFound (template: RequiredTagNotFound, arg…
- SR.UnexpectedXmlTag (template: UnexpectedXmlTag, arg…
- SR.UnsupportedHashAlgorithm
- SR.XmlSignatureParseError
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f395f651457d2fa4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlSignatureManifest.cs:608
{
try
{
// ensure it starts with the correct query prefix
String query = attrValue.Substring(index);
if ((query.Length > _contentTypeQueryStringPrefix.Length) && (query.StartsWith(_contentTypeQueryStringPrefix, StringComparison.Ordinal)))
{
// truncate the prefix and validate
contentType = new ContentType(query.Substring(_contentTypeQueryStringPrefix.Length));
}
// now construct the uri without the query
uri = PackUriHelper.ValidatePartUri(new Uri(attrValue.Substring(0, index), UriKind.Relative));
}
catch (ArgumentException ae)
{
// Content type or part uri is malformed so we have a bad signature.
// Rethrow as XmlException so outer validation loop can catch it and return validation result.
throw new XmlException(SR.PartReferenceUriMalformed, ae);
}
}
// throw if we failed
if (contentType.ToString().Length <= 0)
throw new XmlException(SR.PartReferenceUriMalformed);
return uri;
}
/// <summary>
/// Generates a Reference tag that contains a Relationship transform
/// </summary>
/// <param name="manager">manager</param>
/// <param name="relationshipPartName">name of the relationship part</param>
/// <param name="xDoc">current xml document</param>
/// <param name="hashAlgorithm">hash algorithm = digest method</param>
/// <param name="relationshipSelectors">relationshipSelectors that represent the relationships to sign </param>View on GitHub (pinned to 81131a70a4)