dotnet/wpf · error · FileFormatException
SR.CorruptedData
Error message
SR.CorruptedData
What it means
CertificatePart.GetCertificate throws this FileFormatException with SR.CorruptedData when the X.509 certificate bytes read from the certificate part cannot be constructed into an X509Certificate2 — the part's data is corrupt or not a valid certificate stream.
Solutions
- Verify the certificate part data in the package is not corrupted or oversized
- Re-export the digital signature/certificate part with valid X.509 data
- Catch FileFormatException when opening untrusted XPS packages and surface a corruption error
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs:99 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ccce6b43f676bd09.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs:99
//------------------------------------------------------
/// <summary>
/// Certificate to associate with this Certificate Part
/// </summary>
/// <value></value>
/// <exception cref="FileFormatException">stream is too large</exception>
internal X509Certificate2 GetCertificate()
{
// lazy init
if (_certificate == null)
{
// obtain from the part
using (Stream s = _part.GetStream())
{
if (s.Length > 0)
{
// throw if stream is beyond any reasonable length
if (s.Length > _maximumCertificateStreamLength)
throw new FileFormatException(SR.CorruptedData);
// X509Certificate constructor desires a byte array
Byte[] byteArray = new Byte[s.Length];
PackagingUtilities.ReliableRead(s, byteArray, 0, (int)s.Length);
_certificate = X509CertificateLoader.LoadCertificate(byteArray);
}
}
}
return _certificate;
}
internal void SetCertificate(X509Certificate2 certificate)
{
ArgumentNullException.ThrowIfNull(certificate);
_certificate = certificate;
// persist to the partView on GitHub (pinned to 81131a70a4)