{"record":{"id":"643eaf8f26a2587e","repo":"dotnet/wpf","slug":"sr-urinotabsolute-fonts","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/Fonts.cs","lineNumber":84,"sourceCode":"        /// Enumerates font families in the font location specified by a base URI and/or a location string.\n        /// </summary>\n        /// <param name=\"baseUri\">Base URI used to determine the font location if the location parameter is not specified \n        /// or is relative, and the value of the BaseUri property of each FontFamily in the resulting collection. This\n        /// parameter can be null if the location parameter specifies an absolute location.</param>\n        /// <param name=\"location\">Optional relative or absolute URI reference. The location is used (with baseUri) to \n        /// determine the font folder and is exposed as part of the Source property of each FontFamily in the resulting\n        /// collection. If location is null or empty then \"./\" is implied, meaning same folder as the base URI.</param>\n        /// <returns>Collection of FontFamily objects from the specified font location.</returns>\n        /// <remarks>\n        /// The caller must have FileIOPermission(FileIOPermissionAccess.Read) for the specified font folder.\n        /// Each resulting FontFamily object has the specified base Uri as its BaseUri property and includes the\n        /// specified location as part of the friendly name specified by the Source property.\n        /// </remarks>\n        public static ICollection<FontFamily> GetFontFamilies(Uri baseUri, string location)\n        {\n            // Both Uri parameters are optional but neither can be relative.\n            if (baseUri != null && !baseUri.IsAbsoluteUri)\n                throw new ArgumentException(SR.UriNotAbsolute, nameof(baseUri));\n\n            // Determine the font location from the base URI and location string.\n            Uri fontLocation;\n            if (!string.IsNullOrEmpty(location) && Uri.TryCreate(location, UriKind.Absolute, out fontLocation))\n            {\n                // absolute location; make sure we support absolute font family references for this scheme\n                if (!Util.IsSupportedSchemeForAbsoluteFontFamilyUri(fontLocation))\n                    throw new ArgumentException(SR.InvalidAbsoluteUriInFontFamilyName, nameof(location));\n\n                // make sure the absolute location is a valid URI reference rather than a Win32 path as\n                // we don't support the latter in a font family reference\n                location = fontLocation.GetComponents(UriComponents.AbsoluteUri, UriFormat.SafeUnescaped);\n            }\n            else\n            {\n                // relative location; we need a base URI\n                if (baseUri == null)\n                    throw new ArgumentNullException(nameof(baseUri), SR.Format(SR.NullBaseUriParam, \"baseUri\", \"location\"));","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Fonts.cs#L66-L102","documentation":"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.","triggerScenarios":"Calling GetFontFamilies(relativeUri, \"fonts/\") with a Uri created as UriKind.Relative, or a scheme-less path Uri.","commonSituations":"Passing a relative application folder hoping it resolves against the app base automatically instead of building an absolute Pack URI.","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."],"exampleFix":"// before\nFonts.GetFontFamilies(new Uri(\"resources/fonts\", UriKind.Relative), null);\n// after\nFonts.GetFontFamilies(new Uri(\"pack://application:,,,/MyApp;component/resources/fonts/\"), null);","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 families = Fonts.GetFontFamilies(baseUri, location); }\ncatch (ArgumentException) { /* relative baseUri; build absolute and retry */ }","preventionTips":["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."],"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"}