{"record":{"id":"7a5e7638b5834983","repo":"dotnet/wpf","slug":"sr-urinotabsolute-fontfamily","errorCode":null,"errorMessage":"SR.UriNotAbsolute","messagePattern":"SR\\.UriNotAbsolute","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamily.cs","lineNumber":71,"sourceCode":"        /// of which may be either a regular family name string (e.g., \"Arial\") or a URI\n        /// (e.g., \"file:///c:/windows/fonts/#Arial\").</param>\n        public FontFamily(string familyName) : this(null, familyName)\n        {}\n\n        /// <summary>\n        /// Constructs FontFamily from a string and an optional base URI.\n        /// </summary>\n        /// <param name=\"baseUri\">Specifies the base URI used to resolve family names, typically \n        /// the URI of the document or element that refers to the font family. Can be null.</param>\n        /// <param name=\"familyName\">Specifies one or more comma-separated family names, each\n        /// of which may be either a regular family name string (e.g., \"Arial\") or a URI\n        /// (e.g., \"file:///c:/windows/fonts/#Arial\").</param>\n        public FontFamily(Uri baseUri, string familyName)\n        {\n            ArgumentNullException.ThrowIfNull(familyName);\n\n            if (baseUri != null && !baseUri.IsAbsoluteUri)\n                throw new ArgumentException(SR.UriNotAbsolute, nameof(baseUri));\n\n            _familyIdentifier = new FontFamilyIdentifier(familyName, baseUri);\n        }\n\n        internal FontFamily(FontFamilyIdentifier familyIdentifier)\n        {\n            _familyIdentifier = familyIdentifier;\n        }\n\n        /// <summary>\n        /// Construct an anonymous font family, i.e., a composite font that is created\n        /// programatically instead of referenced by name or URI.\n        /// </summary>\n        public FontFamily()\n        {\n            _familyIdentifier = new FontFamilyIdentifier(null, null);\n            _firstFontFamily = new CompositeFontFamily();\n        }","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamily.cs#L53-L89","documentation":"The FontFamily(Uri baseUri, string familyName) constructor throws this ArgumentException when baseUri is non-null but relative (IsAbsoluteUri is false). A relative base URI cannot resolve font family references, so the library rejects it up front.","triggerScenarios":"Calling new FontFamily(someRelativeUri, \"Arial#Custom\") where someRelativeUri was created with UriKind.Relative, or a Uri built from a path without a scheme.","commonSituations":"Building the base URI from a relative app path like \"fonts/\" without combining it with the application's Pack URI or absolute base directory.","solutions":["Pass an absolute Uri (e.g. new Uri(packUriString, UriKind.Absolute) or a file:/// URI).","Resolve relative paths against a known absolute base before constructing the FontFamily.","Pass null for baseUri if you intend a machine-fonts lookup, instead of a relative Uri."],"exampleFix":"// before\nvar ff = new FontFamily(new Uri(\"fonts/\", UriKind.Relative), \"MyFont#Custom\");\n// after\nvar baseUri = new Uri(\"pack://application:,,,/MyApp;component/fonts/\");\nvar ff = new FontFamily(baseUri, \"MyFont#Custom\");","handlingStrategy":"validation","validationCode":"if (baseUri != null && !baseUri.IsAbsoluteUri)\n    throw new ArgumentException(\"baseUri must be absolute\", nameof(baseUri));","typeGuard":"bool IsValidFontBase(Uri u) => u == null || u.IsAbsoluteUri;","tryCatchPattern":"try { var ff = new FontFamily(baseUri, name); }\ncatch (ArgumentException) { /* baseUri was relative; resolve and retry */ }","preventionTips":["Create base Uris with UriKind.Absolute.","Resolve app-relative paths into Pack URIs before use.","Pass null instead of a relative Uri when you don't need a base."],"tags":["wpf","fonts","uri","argumentexception"],"backgroundTag":"invalid-url-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}