{"record":{"id":"63fa8bedb404550b","repo":"dotnet/wpf","slug":"sr-certificatepartcontenttypemismatch","errorCode":null,"errorMessage":"SR.CertificatePartContentTypeMismatch","messagePattern":"SR\\.CertificatePartContentTypeMismatch","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs","lineNumber":145,"sourceCode":"        /// <summary>\n        /// CertificatePart constructor\n        /// </summary>\n        internal CertificatePart(System.IO.Packaging.Package container, Uri partName)\n        {\n            ArgumentNullException.ThrowIfNull(container);\n            ArgumentNullException.ThrowIfNull(partName);\n\n            partName = PackUriHelper.ValidatePartUri(partName);\n            \n            // create if not found\n            if (container.PartExists(partName))\n            {\n                // open the part\n                _part = container.GetPart(partName);\n\n                // ensure the part is of the expected type\n                if (!_part.ValidatedContentType().AreTypeAndSubTypeEqual(_certificatePartContentType))\n                    throw new FileFormatException(SR.CertificatePartContentTypeMismatch);\n            }\n            else\n            {\n                // create the part\n                _part = container.CreatePart(partName, _certificatePartContentType.ToString());\n            }\n        }\n\n        //------------------------------------------------------\n        //\n        //  Private Fields\n        //\n        //------------------------------------------------------\n        private PackagePart             _part;          // part that houses the certificate\n        private X509Certificate2       _certificate;   // certificate itself\n\n        // certificate part constants\n        private static readonly ContentType _certificatePartContentType =","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs#L127-L163","documentation":"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.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Certificate.cs:145 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}