{"record":{"id":"cd7b43de2e932124","repo":"dotnet/wpf","slug":"the-part-name-does-not-correspond-to-its-content-type","errorCode":null,"errorMessage":"The part name does not correspond to its content type.","messagePattern":"The part name does not correspond to its content type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/DeobfuscatingStream.cs","lineNumber":203,"sourceCode":"        /// <summary>\n        /// Constructor\n        /// </summary>\n        /// <param name=\"obfuscatedStream\">stream that holds obfuscated resource</param>\n        /// <param name=\"streamUri\">the original Uri which is used to obtain obfuscatedStream; it holds\n        ///                         the GUID information which is used to obfuscate the resources</param>\n        /// <param name=\"leaveOpen\">if it is false, obfuscatedStream will be also disposed when\n        ///                         DeobfuscatingStream is disposed</param>\n        /// <remarks>streamUri has to be a pack Uri</remarks>\n        internal DeobfuscatingStream(Stream obfuscatedStream, Uri streamUri, bool leaveOpen)\n        {\n            ArgumentNullException.ThrowIfNull(obfuscatedStream);\n\n            // Make sure streamUri is in the correct form; getting partUri from it will do all necessary checks for error\n            //    conditions; We also have to make sure that it has a part name\n            Uri partUri = System.IO.Packaging.PackUriHelper.GetPartUri(streamUri);\n            if (partUri == null)\n            {\n                throw new InvalidOperationException(SR.InvalidPartName);\n            }\n\n            // Normally we should use PackUriHelper.GetStringForPartUri to get the string representation of part Uri\n            //    however, since we already made sure that streamUris is in the correct form (such as to check if it is an absolute Uri\n            //    and there is a correct authority (package)), it doesn't have to be fully validated again.\n            // Get the escaped string for the part name as part names should have only ascii characters\n            String guid = Path.GetFileNameWithoutExtension(\n                                    streamUri.GetComponents(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.UriEscaped));\n\n            _guid = GetGuidByteArray(guid);\n            _obfuscatedStream = obfuscatedStream;\n            _ownObfuscatedStream = !leaveOpen;\n        }\n\n        #endregion\n\n        //------------------------------------------------------\n        //","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/DeobfuscatingStream.cs#L185-L221","documentation":"DeobfuscatingStream wraps XPS obfuscated font streams (URI form 'pack://.../GUIDGUID/filename'). The stream URI passed to the constructor must resolve to a part URI with a valid part name; PackUriHelper.GetPartUri returned null because the URI does not identify a package part. This library throws InvalidOperationException because a content-type/part-name mismatch means the stream cannot be deobfuscated.","triggerScenarios":"Constructing DeobfuscatingStream with a Uri for which PackUriHelper.GetPartUri(streamUri) returns null — e.g. a URI without a 'pack://' scheme, missing the '/GUID-guid/path' obfuscated-font component, or otherwise not identifying a part inside a package.","commonSituations":"Loading an XPS document whose font part name is malformed or hand-edited; passing a relative or non-pack URI into the obfuscated-font pipeline; custom packaging code building font part URIs without the GUID prefix segment required by the XPS spec.","solutions":["Verify the stream URI is an absolute pack URI pointing at a part (PackUriHelper.IsRelationshipPartUri / GetPartUri non-null) before constructing DeobfuscatingStream","Ensure the part name follows the XPS obfuscated-font convention '/Resources/Fonts/GUIDGUID/fontname.odttf'","Regenerate or re-embed the font part in the XPS package rather than renaming it manually"],"exampleFix":"// before\nvar stream = new DeobfuscatingStream(new Uri(fontPath, UriKind.RelativeOrAbsolute));\n// after\nvar packUri = new Uri(\"pack://application:,,,/\" + fontPath, UriKind.Absolute);\nif (System.IO.Packaging.PackUriHelper.GetPartUri(packUri) == null)\n    throw new ArgumentException(\"Not a valid pack part URI\", nameof(fontPath));\nvar stream = new DeobfuscatingStream(packUri);","handlingStrategy":"validation","validationCode":"if (uri == null || !uri.IsAbsoluteUri || System.IO.Packaging.PackUriHelper.GetPartUri(uri) == null)\n    throw new ArgumentException(\"streamUri must be an absolute pack URI identifying a package part\", nameof(uri));","typeGuard":"static bool IsValidPackPartUri(Uri u) => u != null && u.IsAbsoluteUri && System.IO.Packaging.PackUriHelper.GetPartUri(u) != null;","tryCatchPattern":"try { var s = new DeobfuscatingStream(streamUri); ... } catch (InvalidOperationException ex) { log.Error(\"Invalid XPS font part name\", ex); return null; }","preventionTips":["Always build font part URIs with PackUriHelper rather than string concatenation","Verify XPS font part names follow the GUIDGUID/filename convention","Validate URIs at package-authoring time, not just consumption time"],"tags":["xps","packaging","uri","invalid-part-name"],"backgroundTag":"invalid-argument-format","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"}