{"record":{"id":"254727e479ab8248","repo":"dotnet/wpf","slug":"fileformatexception-new-uri-filename-urikind","errorCode":null,"errorMessage":"FileFormatException(new Uri(fileName, UriKind.RelativeOrAbsolute), message, innerException)","messagePattern":"FileFormatException\\(new Uri\\(fileName, UriKind\\.RelativeOrAbsolute\\), message, innerException\\)","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs","lineNumber":942,"sourceCode":"        {\n            Fail(SR.Format(SR.CompositeFontMissingAttribute, name));\n        }\n\n        /// <summary>\n        ///  Fail with a specified error message.\n        /// </summary>\n        private void Fail(string message)\n        {\n            Fail(message, null);\n        }\n\n        /// <summary>\n        /// Fail with a specified error message and inner exception.\n        /// </summary>\n        private void Fail(string message, Exception innerException)\n        {\n            string fileName = _reader.BaseURI;\n            throw new FileFormatException(new Uri(fileName, UriKind.RelativeOrAbsolute), message, innerException);\n        }\n        #endregion\n\n        private CompositeFontInfo _compositeFontInfo;\n\n        private XmlReader _reader;\n\n        // XML namespaces for which Mapping processing instructions have been read. For each entry,\n        // the key is the XML namespace, and the value is either SystemClrNamespace (if the the \n        // Mapping PI specifies \"System\" and \"MSCORLIB\") or String.Empty (any other Mapping).\n        private Hashtable _namespaceMap;\n\n        // Type converters for double and XmlLanguage types.\n        private TypeConverter _doubleTypeConverter;\n        private TypeConverter _xmlLanguageTypeConverter;\n\n        private const string SystemClrNamespace = \"System\";\n","sourceCodeStart":924,"sourceCodeEnd":960,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs#L924-L960","documentation":"CompositeFontParser.Fail raises FileFormatException with a caller-supplied message and inner exception plus the font file's BaseURI. Called directly or via FailAttributeValue, it means a value in the composite font document is semantically wrong even though the XML parsed.","triggerScenarios":"An attribute value fails semantic validation during CompositeFont parsing (wrong type, unexpected element, invalid enum-ish value), e.g. a required attribute is missing or has an unparsable value passed to FailAttributeValue.","commonSituations":"Hand-authored .CompositeFont files with wrong attribute names/types, schema drift between WPF versions, font resources produced by custom tooling emitting invalid values.","solutions":["Read the exception Message and InnerException to identify the offending attribute","Fix or remove the invalid attribute in the .CompositeFont file","Compare against a working .CompositeFont sample for the expected schema","Log the SourceUri property to know which font file failed"],"exampleFix":"<!-- before: wrong attribute type -->\n<FontFamilyEntry FamilyName=\"Arial\" Weight=\"Bold\" Style=\"0\" />\n<!-- after -->\n<FontFamilyEntry FamilyName=\"Arial\" Weight=\"Bold\" Style=\"Normal\" />","handlingStrategy":"try-catch","validationCode":"// Semantic pre-check example\nif (!Enum.TryParse<FontStyle>(styleAttr, out _)) throw new ArgumentException($\"Invalid Style: {styleAttr}\");","typeGuard":null,"tryCatchPattern":"try { ParseCompositeFont(reader); }\ncatch (FileFormatException e)\n{\n    log.Error($\"Invalid value in font file {e.SourceUri}: {e.Message}\", e.InnerException);\n}","preventionTips":["Validate attribute values against the CompositeFont schema before parsing","Log FileFormatException.SourceUri to locate the offending file","Compare against a known-good .CompositeFont template"],"tags":["wpf","fonts","fileformatexception","parsing"],"backgroundTag":"invalid-argument-value","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"}