{"record":{"id":"1f403b90f57f08d7","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloaderdiscardcontrolhasincorrecttype","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderDiscardControlHasIncorrectType","messagePattern":"SR\\.XpsValidatingLoaderDiscardControlHasIncorrectType","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs","lineNumber":631,"sourceCode":"                checkRels = package.GetRelationshipsByType(_discardControlRel);\n                count = 0;\n                foreach (PackageRelationship rel in checkRels)\n                {\n                    count++;\n                    if (count > 1)\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderMoreThanOneDiscardControlInPackage);\n                    }\n\n                    // Also check for existence and type\n                    Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);\n                    Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);\n\n                    PackagePart targetPart = package.GetPart(targetUri);\n\n                    if (!_discardControlContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderDiscardControlHasIncorrectType);\n                    }\n                }\n\n                // This is the XPS payload root part. We also should check if the Package only has at most one thumbnail...\n                checkRels = package.GetRelationshipsByType(_thumbnailRel);\n                count = 0;\n                foreach (PackageRelationship rel in checkRels)\n                {\n                    count++;\n                    if (count > 1)\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderMoreThanOneThumbnailInPackage);\n                    }\n\n                    // Also check for existence and type\n                    Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);\n                    Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);\n","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs#L613-L649","documentation":"The XPS validating loader found a FixedPage's DiscardControl part whose content type does not match the required discard-control MIME type. The loader validates every part referenced via the discard-control relationship and throws FileFormatException to reject malformed or tampered XPS packages rather than loading them with an invalid payload part.","triggerScenarios":"Loading an XPS document (XpsDocument/FixedDocumentSequence) whose FixedPage has a DiscardControl relationship targeting a part whose ContentType is not the required discard-control type/subtype — e.g. the part was renamed, rewritten by a custom packaging tool, or points at the wrong part.","commonSituations":"Hand-built or third-party-generated XPS packages with wrong ContentTypes entries in [Content_Types].xml; files edited/re-zipped by scripts that change part names; corrupted downloads where a different part replaced the discard control part.","solutions":["Regenerate or fix the XPS package so the DiscardControl part's content type matches the required discard-control content type in [Content_Types].xml.","Open the package and inspect the target part's ContentType; correct the Override/Default entry in [Content_Types].xml.","Remove the DiscardControl relationship if discarding is not needed, so validation skips that part.","Catch FileFormatException at load time and treat the document as invalid/re-fetch a clean copy."],"exampleFix":"// before ([Content_Types].xml missing/wrong override for /Documents/1/Page1.fpage/_rels/discard.xml)\n<Default Extension=\"xml\" ContentType=\"application/octet-stream\" />\n// after\n<Override PartName=\"/Documents/1/Page1.fpage/_rels/discard.xml\" ContentType=\"application/vnd.ms-package.discard-control+xml\" />","handlingStrategy":"validation","validationCode":"static bool HasValidDiscardControl(Package package, Uri partUri, string discardTarget)\n{\n    var target = PackUriHelper.ResolvePartUri(partUri, new Uri(discardTarget, UriKind.Relative));\n    return package.PartExists(target) &&\n        string.Equals(new ContentType(package.GetPart(target).ContentType).ToString(), \"application/vnd.ms-package.discard-control+xml\", StringComparison.OrdinalIgnoreCase);\n}","typeGuard":null,"tryCatchPattern":"try { var doc = new XpsDocument(pkgPath, FileAccess.Read); }\ncatch (FileFormatException ex) { /* reject/repair malformed package */ }","preventionTips":["Validate [Content_Types].xml entries after generating or editing XPS packages.","Use a conformant XPS producer instead of hand-zipping parts.","Re-run package validation after any post-processing of the XPS."],"tags":["xps","file-format","validation","wpf"],"backgroundTag":"schema-validation-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}