dotnet/wpf · error · FileFormatException
FileFormatException(new Uri(_reader.BaseURI…
Error message
FileFormatException(new Uri(_reader.BaseURI, UriKind.RelativeOrAbsolute), x)
What it means
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.
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
Example fix
<!-- before: malformed --> <FontFamily> <FontFamilyEntry FamilyName="Arial" <!-- after: well-formed --> <FontFamily> <FontFamilyEntry FamilyName="Arial" /> </FontFamily>
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate with XDocument document = System.Xml.Linq.XDocument.Load(path, LoadOptions.None); // throws XmlException early if malformed
Type guard
bool IsLoadableXml(string path) { try { XDocument.Load(path); return true; } catch { return false; } } Try / catch
try { LoadFontFamily(uri); }
catch (FileFormatException e) when (e.InnerException is System.Xml.XmlException xe)
{
log.Error($"Malformed CompositeFont XML in {e.SourceUri} at line {xe.LineNumber}: {xe.Message}");
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- FileFormatException(new Uri(fileName…
- " }} " element found. Expected fixed page element ( }} ).
- 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/26500612c2a1d33f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs:872
/// <summary>
/// Make sure the minimum required information is specified.
/// </summary>
private void VerifyCompositeFontInfo()
{
if (_compositeFontInfo.FamilyMaps.Count == 0)
Fail(SR.Format(SR.CompositeFontMissingElement, FamilyMapElement));
if (_compositeFontInfo.FamilyNames.Count == 0)
Fail(SR.Format(SR.CompositeFontMissingElement, StringElement));
}
/// <summary>
/// Fail because of an XML exception.
/// </summary>
private void FailNotWellFormed(Exception x)
{
throw new FileFormatException(new Uri(_reader.BaseURI, UriKind.RelativeOrAbsolute), x);
}
/// <summary>
/// Fail because of an incorrect attribute value.
/// </summary>
private void FailAttributeValue()
{
Fail(SR.Format(
SR.CompositeFontAttributeValue1,
_reader.LocalName));
}
/// <summary>
/// Fail because of an incorrect attribute value with an inner exception.
/// </summary>
private void FailAttributeValue(Exception x)
{
Fail(SR.Format(View on GitHub (pinned to 81131a70a4)