dotnet/wpf · error · FileFormatException
FileFormatException(new Uri(fileName…
Error message
FileFormatException(new Uri(fileName, UriKind.RelativeOrAbsolute), message, innerException)
What it means
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.
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
Example fix
<!-- before: wrong attribute type --> <FontFamilyEntry FamilyName="Arial" Weight="Bold" Style="0" /> <!-- after --> <FontFamilyEntry FamilyName="Arial" Weight="Bold" Style="Normal" />
Defensive patterns
Strategy: try-catch
Validate before calling
// Semantic pre-check example
if (!Enum.TryParse<FontStyle>(styleAttr, out _)) throw new ArgumentException($"Invalid Style: {styleAttr}"); Try / catch
try { ParseCompositeFont(reader); }
catch (FileFormatException e)
{
log.Error($"Invalid value in font file {e.SourceUri}: {e.Message}", e.InnerException);
} Prevention
- Validate attribute values against the CompositeFont schema before parsing
- Log FileFormatException.SourceUri to locate the offending file
- Compare against a known-good .CompositeFont template
When it happens
Trigger: 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.
Common situations: Hand-authored .CompositeFont files with wrong attribute names/types, schema drift between WPF versions, font resources produced by custom tooling emitting invalid values.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- FileFormatException(new Uri(_reader.BaseURI…
- SR.CompositeFontInvalidUnicodeRange
- Count must be 1 when CommitPolicies is set to…
- errMsg (dynamic: message of caught…
- FileFormatException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/254727e479ab8248.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs:942
{
Fail(SR.Format(SR.CompositeFontMissingAttribute, name));
}
/// <summary>
/// Fail with a specified error message.
/// </summary>
private void Fail(string message)
{
Fail(message, null);
}
/// <summary>
/// Fail with a specified error message and inner exception.
/// </summary>
private void Fail(string message, Exception innerException)
{
string fileName = _reader.BaseURI;
throw new FileFormatException(new Uri(fileName, UriKind.RelativeOrAbsolute), message, innerException);
}
#endregion
private CompositeFontInfo _compositeFontInfo;
private XmlReader _reader;
// XML namespaces for which Mapping processing instructions have been read. For each entry,
// the key is the XML namespace, and the value is either SystemClrNamespace (if the the
// Mapping PI specifies "System" and "MSCORLIB") or String.Empty (any other Mapping).
private Hashtable _namespaceMap;
// Type converters for double and XmlLanguage types.
private TypeConverter _doubleTypeConverter;
private TypeConverter _xmlLanguageTypeConverter;
private const string SystemClrNamespace = "System";
View on GitHub (pinned to 81131a70a4)