{"record":{"id":"c1baec9d04aa4398","repo":"AvaloniaUI/Avalonia","slug":"base-uri-must-be-an-absolute-uri","errorCode":null,"errorMessage":"Base uri must be an absolute uri.","messagePattern":"Base uri must be an absolute uri\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/FontFamily.cs","lineNumber":41,"sourceCode":"        {\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"T:Avalonia.Media.FontFamily\" /> class.\n        /// </summary>\n        /// <param name=\"baseUri\">Specifies the base uri that is used to resolve font family assets.</param>\n        /// <param name=\"name\">The name of the <see cref=\"T:Avalonia.Media.FontFamily\" />.</param>\n        /// <exception cref=\"T:System.ArgumentException\">Base uri must be an absolute uri.</exception>\n        public FontFamily(Uri? baseUri, string name)\n        {\n            if (string.IsNullOrEmpty(name))\n            {\n                throw new ArgumentNullException(nameof(name));\n            }\n\n            if (baseUri != null && !baseUri.IsAbsoluteUri)\n            {\n                throw new ArgumentException(\"Base uri must be an absolute uri.\", nameof(baseUri));\n            }\n\n            var fontSources = GetFontSourceIdentifier(name);\n\n            FamilyNames = new FamilyNameCollection(fontSources);\n\n            if (fontSources.Count == 1)\n            {\n                var singleSource = fontSources[0];\n\n                if (singleSource.Source is Uri source)\n                {\n                    if (source.IsAbsoluteUri)\n                    {\n                        Key = new FontFamilyKey(source);\n                    }\n                    else\n                    {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/FontFamily.cs#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar uri = new Uri(\"Assets/Fonts\", UriKind.Relative);\nvar ff = new FontFamily(uri, \"MyFont\");\n\n// after\nvar ff = new FontFamily(null, \"avares://MyApp/Assets/Fonts#MyFont\");\n// or absolute base:\nvar baseUri = new Uri(\"avares://MyApp/\", UriKind.Absolute);\nvar ff = new FontFamily(baseUri, \"Assets/Fonts#MyFont\");","handlingStrategy":"validation","validationCode":"if (baseUri is not null && !baseUri.IsAbsoluteUri)\n    baseUri = null; // or build an absolute URI\nvar ff = new FontFamily(baseUri, name);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["font-family","uri","media","resource"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}