{"record":{"id":"26500612c2a1d33f","repo":"dotnet/wpf","slug":"fileformatexception-new-uri-reader-baseuri-urikind","errorCode":null,"errorMessage":"FileFormatException(new Uri(_reader.BaseURI, UriKind.RelativeOrAbsolute), x)","messagePattern":"FileFormatException\\(new Uri\\(_reader\\.BaseURI, UriKind\\.RelativeOrAbsolute\\), x\\)","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs","lineNumber":872,"sourceCode":"\n        /// <summary>\n        /// Make sure the minimum required information is specified.\n        /// </summary>\n        private void VerifyCompositeFontInfo()\n        {\n            if (_compositeFontInfo.FamilyMaps.Count == 0)\n                Fail(SR.Format(SR.CompositeFontMissingElement, FamilyMapElement));\n\n            if (_compositeFontInfo.FamilyNames.Count == 0)\n                Fail(SR.Format(SR.CompositeFontMissingElement, StringElement));\n        }\n\n        /// <summary>\n        /// Fail because of an XML exception.\n        /// </summary>\n        private void FailNotWellFormed(Exception x)\n        {\n            throw new FileFormatException(new Uri(_reader.BaseURI, UriKind.RelativeOrAbsolute), x);\n        }\n\n        /// <summary>\n        /// Fail because of an incorrect attribute value.\n        /// </summary>\n        private void FailAttributeValue()\n        {\n            Fail(SR.Format(\n                SR.CompositeFontAttributeValue1,\n                _reader.LocalName));\n        }\n\n        /// <summary>\n        /// Fail because of an incorrect attribute value with an inner exception.\n        /// </summary>\n        private void FailAttributeValue(Exception x)\n        {\n            Fail(SR.Format(","sourceCodeStart":854,"sourceCodeEnd":890,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs#L854-L890","documentation":"FailNotWellFormed wraps any XmlException raised while reading a composite font (.CompositeFont) into a FileFormatException carrying the source URI and the original XML exception as InnerException. It signals that the font description file is not well-formed XML.","triggerScenarios":"XmlReader encounters malformed XML (unclosed tags, invalid characters, encoding errors) while CompositeFontParser walks the document — e.g. when WPF loads a font family from a CompositeFont resource.","commonSituations":"Truncated .CompositeFont file, wrong encoding/BOM, XML edited by hand or by a build step that broke escaping, font resource served over a stream that got cut off.","solutions":["Open the .CompositeFont file in an XML editor / xmllint to find the malformed region","Inspect InnerException for the exact line/position of the XML error","Restore the file from a known-good source or regenerate it","Verify the file encoding matches the declared XML encoding"],"exampleFix":"<!-- before: malformed -->\n<FontFamily>\n  <FontFamilyEntry FamilyName=\"Arial\"\n<!-- after: well-formed -->\n<FontFamily>\n  <FontFamilyEntry FamilyName=\"Arial\" />\n</FontFamily>","handlingStrategy":"try-catch","validationCode":"// Pre-validate with XDocument\ndocument = System.Xml.Linq.XDocument.Load(path, LoadOptions.None); // throws XmlException early if malformed","typeGuard":"bool IsLoadableXml(string path) { try { XDocument.Load(path); return true; } catch { return false; } }","tryCatchPattern":"try { LoadFontFamily(uri); }\ncatch (FileFormatException e) when (e.InnerException is System.Xml.XmlException xe)\n{\n    log.Error($\"Malformed CompositeFont XML in {e.SourceUri} at line {xe.LineNumber}: {xe.Message}\");\n}","preventionTips":["Run xmllint over .CompositeFont files in CI","Keep font resources under source control, never hand-edit deployed copies","Preserve file encoding and BOM during build steps"],"tags":["wpf","fonts","xml","fileformatexception"],"backgroundTag":"xml-parse-error","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"}