dotnet/wpf · error · ArgumentException
SR.InvalidAbsoluteUriInFontFamilyName
Error message
SR.InvalidAbsoluteUriInFontFamilyName
What it means
Fonts.GetFontFamilies throws this ArgumentException when the 'location' string parses as an absolute Uri but its scheme is not supported for absolute font family references (Util.IsSupportedSchemeForAbsoluteFontFamilyUri fails). The library only allows specific schemes (pack, file, http/https) in absolute font locations.
Solutions
- Use a supported scheme (pack, file, or http/https) in the location.
- For a network path, copy fonts locally or serve over a supported scheme.
- Pass the location as a relative string plus an absolute baseUri instead.
Example fix
// before Fonts.GetFontFamilies(null, "ftp://server/fonts"); // after Fonts.GetFontFamilies(null, "file:///server/fonts");
Defensive patterns
Strategy: validation
Validate before calling
if (Uri.TryCreate(location, UriKind.Absolute, out var abs)
&& !(abs.Scheme == Uri.UriSchemeFile || abs.Scheme == Uri.UriSchemeHttp || abs.Scheme == Uri.UriSchemeHttps || abs.Scheme == "pack"))
throw new ArgumentException("unsupported scheme", nameof(location)); Try / catch
try { Fonts.GetFontFamilies(null, location); }
catch (ArgumentException) { /* unsupported absolute scheme; reformat location */ } Prevention
- Restrict font locations to file, http(s), or pack schemes.
- Prefer relative locations with an absolute baseUri over custom-scheme absolute Uris.
- Copy fonts from exotic sources (ftp, shares) to a local file path first.
When it happens
Trigger: Calling GetFontFamilies(baseUri, "ftp://server/fonts") or any absolute Uri with an unsupported scheme (ftp, ldap, custom app schemes).
Common situations: Pointing font enumeration at a network share via a non-HTTP UNC-style or custom protocol string that happens to parse as an absolute Uri.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- SR.Format(SR.NullBaseUriParam, "baseUri", "location")
- SR.UriNotAbsolute
- SR.UriNotAbsolute
- SR.UriNotAbsolute
- UriSchemeMismatch (pack)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ee3d749fe0cdec4d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Fonts.cs:92
/// <returns>Collection of FontFamily objects from the specified font location.</returns>
/// <remarks>
/// The caller must have FileIOPermission(FileIOPermissionAccess.Read) for the specified font folder.
/// Each resulting FontFamily object has the specified base Uri as its BaseUri property and includes the
/// specified location as part of the friendly name specified by the Source property.
/// </remarks>
public static ICollection<FontFamily> GetFontFamilies(Uri baseUri, string location)
{
// Both Uri parameters are optional but neither can be relative.
if (baseUri != null && !baseUri.IsAbsoluteUri)
throw new ArgumentException(SR.UriNotAbsolute, nameof(baseUri));
// Determine the font location from the base URI and location string.
Uri fontLocation;
if (!string.IsNullOrEmpty(location) && Uri.TryCreate(location, UriKind.Absolute, out fontLocation))
{
// absolute location; make sure we support absolute font family references for this scheme
if (!Util.IsSupportedSchemeForAbsoluteFontFamilyUri(fontLocation))
throw new ArgumentException(SR.InvalidAbsoluteUriInFontFamilyName, nameof(location));
// make sure the absolute location is a valid URI reference rather than a Win32 path as
// we don't support the latter in a font family reference
location = fontLocation.GetComponents(UriComponents.AbsoluteUri, UriFormat.SafeUnescaped);
}
else
{
// relative location; we need a base URI
if (baseUri == null)
throw new ArgumentNullException(nameof(baseUri), SR.Format(SR.NullBaseUriParam, "baseUri", "location"));
// the location part must include a path component, otherwise we'll look in windows fonts and ignore the base URI
if (string.IsNullOrEmpty(location))
location = "./";
else if (Util.IsReferenceToWindowsFonts(location))
location = "./" + location;
fontLocation = new Uri(baseUri, location);View on GitHub (pinned to 81131a70a4)