AvaloniaUI/Avalonia · error · ArgumentException
Base uri must be an absolute uri.
Error message
Base uri must be an absolute uri.
What it means
The FontFamily constructor throws ArgumentException when a non-null baseUri is provided but is not absolute. Font asset resolution requires an absolute base URI to correctly locate font resources; a relative base URI would make resolution ambiguous. Pass null (to indicate no base) or a fully-qualified absolute URI.
Source
Thrown at src/Avalonia.Base/Media/FontFamily.cs:41
{
}
/// <summary>
/// Initializes a new instance of the <see cref="T:Avalonia.Media.FontFamily" /> class.
/// </summary>
/// <param name="baseUri">Specifies the base uri that is used to resolve font family assets.</param>
/// <param name="name">The name of the <see cref="T:Avalonia.Media.FontFamily" />.</param>
/// <exception cref="T:System.ArgumentException">Base uri must be an absolute uri.</exception>
public FontFamily(Uri? baseUri, string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException(nameof(name));
}
if (baseUri != null && !baseUri.IsAbsoluteUri)
{
throw new ArgumentException("Base uri must be an absolute uri.", nameof(baseUri));
}
var fontSources = GetFontSourceIdentifier(name);
FamilyNames = new FamilyNameCollection(fontSources);
if (fontSources.Count == 1)
{
var singleSource = fontSources[0];
if (singleSource.Source is Uri source)
{
if (source.IsAbsoluteUri)
{
Key = new FontFamilyKey(source);
}
else
{View on GitHub (pinned to 11c5427268)
Solutions
- Pass an absolute URI (e.g. with 'resm:' or 'avares://' scheme) or pass null for baseUri.
- If you have a relative path, combine it with an absolute base first: new Uri(absoluteBase, relativePath).
- Use FontFamily.Parse(s, baseUri) only when baseUri is absolute or null.
Example fix
// before
var uri = new Uri("Assets/Fonts", UriKind.Relative);
var ff = new FontFamily(uri, "MyFont");
// after
var ff = new FontFamily(null, "avares://MyApp/Assets/Fonts#MyFont");
// or absolute base:
var baseUri = new Uri("avares://MyApp/", UriKind.Absolute);
var ff = new FontFamily(baseUri, "Assets/Fonts#MyFont"); Defensive patterns
Strategy: validation
Validate before calling
if (baseUri is not null && !baseUri.IsAbsoluteUri)
baseUri = null; // or build an absolute URI
var ff = new FontFamily(baseUri, name); Prevention
- Pass null for baseUri when you have no absolute base.
- Use pack/application schemes (avares://, resm:) for absolute font URIs.
- Validate IsAbsoluteUri before constructing FontFamily with a base.
When it happens
Trigger: Calling new FontFamily(baseUri, name) where baseUri is a relative Uri (IsAbsoluteUri == false). Common when constructing a FontFamily from a XAML base URI that was built relatively, or when passing a Uri created without a scheme.
Common situations: Using `new Uri("path/to/fonts", UriKind.Relative)` as a base URI. Passing a XAML baseUri from a context that yielded a relative URI. Manually constructing font asset URIs without a pack/application scheme.
Related errors
- Specified family is not supported.
- Font collection Key should follow the fonts: scheme.
- File path is expected to be an absolute link with "file" or
- Folder path is expected to be an absolute link with "file" o
- Invalid brush string: '{s}'.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/c1baec9d04aa4398.
Report an issue: GitHub.