dotnet/wpf · error · FileFormatException
SR.CertificatePartContentTypeMismatch
Error message
SR.CertificatePartContentTypeMismatch
What it means
The CertificatePart constructor throws this FileFormatException when the existing package part at partName has a content type that does not match the expected certificate-part content type. The package contains a part at the certificate location that is not a certificate part.
Solutions
- Ensure the certificate part's content type is the standard package certificate content type
- Re-save the package so the certificate part is stored with the correct content type
- Catch the mismatch exception when opening untrusted packages
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs:145 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- SSL/TLS and certificate errors — how TLS handshakes and certificate validation fail.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/63fa8bedb404550b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs:145
/// <summary>
/// CertificatePart constructor
/// </summary>
internal CertificatePart(System.IO.Packaging.Package container, Uri partName)
{
ArgumentNullException.ThrowIfNull(container);
ArgumentNullException.ThrowIfNull(partName);
partName = PackUriHelper.ValidatePartUri(partName);
// create if not found
if (container.PartExists(partName))
{
// open the part
_part = container.GetPart(partName);
// ensure the part is of the expected type
if (!_part.ValidatedContentType().AreTypeAndSubTypeEqual(_certificatePartContentType))
throw new FileFormatException(SR.CertificatePartContentTypeMismatch);
}
else
{
// create the part
_part = container.CreatePart(partName, _certificatePartContentType.ToString());
}
}
//------------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
private PackagePart _part; // part that houses the certificate
private X509Certificate2 _certificate; // certificate itself
// certificate part constants
private static readonly ContentType _certificatePartContentType =View on GitHub (pinned to 81131a70a4)