{"record":{"id":"a518ab91759fd593","repo":"dotnet/wpf","slug":"sr-format-sr-nullbaseuriparam-baseuri-location","errorCode":null,"errorMessage":"SR.Format(SR.NullBaseUriParam, \"baseUri\", \"location\")","messagePattern":"SR\\.Format\\(SR\\.NullBaseUriParam, \"baseUri\", \"location\"\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Fonts.cs","lineNumber":102,"sourceCode":"                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\"));\n\n                // the location part must include a path component, otherwise we'll look in windows fonts and ignore the base URI\n                if (string.IsNullOrEmpty(location))\n                    location = \"./\";\n                else if (Util.IsReferenceToWindowsFonts(location))\n                    location = \"./\" + location;\n\n                fontLocation = new Uri(baseUri, location);\n            }\n\n            // Create the font families.\n            return CreateFamilyCollection(\n                fontLocation,   // fontLocation\n                baseUri,        // fontFamilyBaseUri\n                location        // fontFamilyLocationReference\n                );\n        }\n","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Fonts.cs#L84-L120","documentation":"Fonts.GetFontFamilies throws this ArgumentNullException when 'location' is relative (not an absolute Uri) and 'baseUri' is null, because a relative location cannot be resolved without a base. The message names both parameters to explain the relationship.","triggerScenarios":"Calling GetFontFamilies(null, \"resources/fonts/\") — location is a relative path and no base Uri was supplied.","commonSituations":"Assuming the method defaults the base to the application directory or Windows fonts folder when only a relative path is given.","solutions":["Supply an absolute baseUri: GetFontFamilies(new Uri(\"pack://application:,,,/MyApp;component/\"), \"resources/fonts/\").","Make 'location' itself an absolute Uri string instead.","For machine fonts, use system font enumeration rather than an empty baseUri."],"exampleFix":"// before\nFonts.GetFontFamilies(null, \"resources/fonts/\");\n// after\nFonts.GetFontFamilies(new Uri(\"pack://application:,,,/MyApp;component/\"), \"resources/fonts/\");","handlingStrategy":"validation","validationCode":"if (baseUri == null && string.IsNullOrEmpty(location))\n    throw new ArgumentNullException(nameof(baseUri));\nif (baseUri == null && Uri.TryCreate(location, UriKind.Relative, out _))\n    throw new ArgumentException(\"location is relative; baseUri required\", nameof(baseUri));","typeGuard":null,"tryCatchPattern":"try { Fonts.GetFontFamilies(baseUri, location); }\ncatch (ArgumentNullException) { /* supply an absolute baseUri for relative locations */ }","preventionTips":["Always pair relative location strings with an absolute baseUri.","Use fully absolute font location strings when no base is available.","Validate parameters at the call site before invoking GetFontFamilies."],"tags":["wpf","fonts","argumentnullexception","uri"],"backgroundTag":"missing-required-argument","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"}