dotnet/wpf · error · ArgumentException
SR.UriNotAbsolute
Error message
SR.UriNotAbsolute
What it means
Fonts.GetFontFamilies(Uri baseUri, string location) throws this ArgumentException when baseUri is non-null but not an absolute Uri. The enumeration needs a resolvable absolute base to locate font resources, matching the FontFamily(Uri, string) contract.
Solutions
- Pass an absolute Uri (pack://application:,,,/... or file:///...).
- Resolve the relative path against an absolute base before the call.
- Pass null for baseUri when location is itself an absolute Uri string.
Example fix
// before
Fonts.GetFontFamilies(new Uri("resources/fonts", UriKind.Relative), null);
// after
Fonts.GetFontFamilies(new Uri("pack://application:,,,/MyApp;component/resources/fonts/"), null); Defensive patterns
Strategy: validation
Validate before calling
if (baseUri != null && !baseUri.IsAbsoluteUri)
throw new ArgumentException("baseUri must be absolute", nameof(baseUri)); Type guard
bool IsValidFontBase(Uri u) => u == null || u.IsAbsoluteUri;
Try / catch
try { var families = Fonts.GetFontFamilies(baseUri, location); }
catch (ArgumentException) { /* relative baseUri; build absolute and retry */ } Prevention
- Build base Uris with UriKind.Absolute (Pack URIs for app resources).
- Pass null rather than a relative Uri when location is absolute.
- Centralize Pack URI construction in a helper.
When it happens
Trigger: Calling GetFontFamilies(relativeUri, "fonts/") with a Uri created as UriKind.Relative, or a scheme-less path Uri.
Common situations: Passing a relative application folder hoping it resolves against the app base automatically instead of building an absolute Pack URI.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- SR.UriNotAbsolute
- SR.Collection_BadRank
- SR.FamilyMap_TargetNotSet
- SR.Format(SR.General_Expected_Type, "FontFamily")
- SR.Format(SR.NullBaseUriParam, "baseUri", "location")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/643eaf8f26a2587e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Fonts.cs:84
/// Enumerates font families in the font location specified by a base URI and/or a location string.
/// </summary>
/// <param name="baseUri">Base URI used to determine the font location if the location parameter is not specified
/// or is relative, and the value of the BaseUri property of each FontFamily in the resulting collection. This
/// parameter can be null if the location parameter specifies an absolute location.</param>
/// <param name="location">Optional relative or absolute URI reference. The location is used (with baseUri) to
/// determine the font folder and is exposed as part of the Source property of each FontFamily in the resulting
/// collection. If location is null or empty then "./" is implied, meaning same folder as the base URI.</param>
/// <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"));View on GitHub (pinned to 81131a70a4)