dotnet/wpf · error · ArgumentException
SR.FamilyMap_TargetNotSet
Error message
SR.FamilyMap_TargetNotSet
What it means
CompositeFontInfo.PrepareToAddFamilyMap validates a FontFamilyMap before adding it to a composite font (font family fallback) definition. A family map must have a non-null, non-empty Target (the target font family name); otherwise it throws ArgumentException(SR.FamilyMap_TargetNotSet).
Solutions
- Set familyMap.Target (e.g. to a font family name like "Segoe UI") before adding the map.
- Fix the composite font XAML so every <FontFamilyMap> has a Target attribute.
- Validate Target non-empty in your own code before invoking the add operation.
Example fix
// before
var map = new FontFamilyMap { Language = XmlLanguage.GetLanguage("ja-JP") };
compositeFont.PrepareToAddFamilyMap(map); // throws: Target not set
// after
var map = new FontFamilyMap { Language = XmlLanguage.GetLanguage("ja-JP"), Target = "Yu Gothic" };
compositeFont.PrepareToAddFamilyMap(map); Defensive patterns
Strategy: validation
Validate before calling
if (familyMap == null) throw new ArgumentNullException(nameof(familyMap));
if (string.IsNullOrEmpty(familyMap.Target))
throw new ArgumentException("FontFamilyMap.Target must be set before adding."); Type guard
bool IsValidFamilyMap(FontFamilyMap m) => m != null && !string.IsNullOrEmpty(m.Target);
Try / catch
try { compositeFont.PrepareToAddFamilyMap(map); }
catch (ArgumentException) { /* fix or skip the family map */ } Prevention
- Always set Target on FontFamilyMap before adding.
- Validate composite font XAML: every FontFamilyMap needs Target.
- Check hand-edited CompositeFont resources for missing attributes.
When it happens
Trigger: Adding a FontFamilyMap to a CompositeFontInfo where familyMap.Target was never assigned — e.g. constructing a FontFamilyMap in code and calling the add API before setting Target, or parsing a malformed composite font where the FontFamily element's Target attribute is missing.
Common situations: Programmatic composition of a font fallback list; hand-written or corrupted .xaml/CompositeFont resources missing the Target attribute for a FamilyMap entry; XAML parsers registering family maps during CompositeFont loading.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- SR.Format(SR.PropertyValueCannotBeNaN, propertyName)
- SR.Collection_BadRank
- SR.Format(SR.General_Expected_Type, "FontFamily")
- SR.Format(SR.PropertyCannotBeNegative, propertyName)
- SR.Format(SR.PropertyMustBeGreaterThanZero, propertyName)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1fb09b144a2bf3bf.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontInfo.cs:48
/// Construct a composite font
/// </summary>
internal CompositeFontInfo()
{
_familyNames = new LanguageSpecificStringDictionary(new Dictionary<XmlLanguage,string>(InitialCultureCount));
_familyMaps = new FontFamilyMapCollection(this);
_defaultFamilyMapRanges = EmptyFamilyMapRanges;
}
/// <summary>
/// Called by FontFamilyMapCollection when a FontFamilyMap is being added.
/// </summary>
internal void PrepareToAddFamilyMap(FontFamilyMap familyMap)
{
// Validate parameters.
ArgumentNullException.ThrowIfNull(familyMap);
if (string.IsNullOrEmpty(familyMap.Target))
throw new ArgumentException(SR.FamilyMap_TargetNotSet);
// If it's culture-specific make sure it's in the hash table.
if (familyMap.Language != null)
{
if (_familyMapRangesByLanguage == null)
{
_familyMapRangesByLanguage = new Dictionary<XmlLanguage, ushort[]>(InitialCultureCount);
_familyMapRangesByLanguage.Add(familyMap.Language, EmptyFamilyMapRanges);
}
else if (!_familyMapRangesByLanguage.ContainsKey(familyMap.Language))
{
_familyMapRangesByLanguage.Add(familyMap.Language, EmptyFamilyMapRanges);
}
}
}
#region family map ranges (skip lists)
View on GitHub (pinned to 81131a70a4)