dotnet/wpf · error · ArgumentException
SR.UriNotAbsolute
Error message
SR.UriNotAbsolute
What it means
GlyphTypeface.Initialize (called from the constructor and from ISupportInitialize.EndInit) requires typefaceSource to be an absolute URI (file:///C:/Fonts/segoeui.ttf or pack://...). A relative URI like "fonts/my.ttf" or "segoeui.ttf" leaves the font unresolvable, so the library throws ArgumentException(SR.UriNotAbsolute, nameof(typefaceSource)) immediately.
Solutions
- Resolve the font path to an absolute URI before constructing: new GlyphTypeface(new Uri(Path.GetFullPath(fontPath))) or new Uri(fontPath, UriKind.Absolute).
- If the path comes from configuration, combine it with AppContext.BaseDirectory: new Uri(Path.Combine(AppContext.BaseDirectory, relativeFontPath)).
- Validate with uri.IsAbsoluteUri before calling and surface a clear error otherwise.
Example fix
// before
var typeface = new GlyphTypeface(new Uri("Fonts/segoeui.ttf")); // ArgumentException: UriNotAbsolute
// after
string fontPath = Path.Combine(AppContext.BaseDirectory, "Fonts", "segoeui.ttf");
var typeface = new GlyphTypeface(new Uri(fontPath, UriKind.Absolute)); Defensive patterns
Strategy: validation
Validate before calling
static Uri ToAbsoluteFontUri(string fontPath)
{
var uri = new Uri(fontPath, UriKind.RelativeOrAbsolute);
if (!uri.IsAbsoluteUri)
uri = new Uri(Path.Combine(AppContext.BaseDirectory, fontPath), UriKind.Absolute);
return uri;
}
// call before: var typeface = new GlyphTypeface(ToAbsoluteFontUri(fontPath)); Type guard
static bool IsAbsoluteFontUri(Uri uri) => uri is not null && uri.IsAbsoluteUri;
Try / catch
try { var typeface = new GlyphTypeface(fontUri); }
catch (ArgumentException ex) when (ex.ParamName == "typefaceSource")
{
// resolve the configured path against the app base directory and retry once
} Prevention
- Store absolute font paths (or resolve against AppContext.BaseDirectory) wherever font paths come from config.
- Always call new Uri(path, UriKind.Absolute) or check IsAbsoluteUri before constructing GlyphTypeface.
- On cross-platform apps, build URIs with Path.Combine plus a base directory rather than hard-coded absolute paths.
When it happens
Trigger: new GlyphTypeface(new Uri("myfont.ttf")) or new GlyphTypeface(new Uri(relativePath, UriKind.Relative)); passing a URI built from a config string that is relative to the app directory; EndInit on a GlyphTypeface whose Source was assigned a relative URI.
Common situations: Loading fonts from config or app settings where only a file name was stored; project files that used relative content paths; copying samples where the font path string happened to be absolute on the sample machine but not yours; Linux/macOS paths without the file:// scheme.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- styleSimulations
- FileFormatException
- SR.AbsoluteUriNotAllowed
- SR.Format(SR.ArgumentPropertyMustNotBeNull,"resourceLocator"…
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriContent"…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/798790fc39addd3b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphTypeface.cs:116
_fontFace = new FontFaceLayoutInfo(font);
_fontSource = new FontSource(typefaceSource);
Invariant.Assert( styleSimulations == StyleSimulations.None
|| styleSimulations == StyleSimulations.ItalicSimulation
|| styleSimulations == StyleSimulations.BoldSimulation
|| styleSimulations == StyleSimulations.BoldItalicSimulation);
_styleSimulations = styleSimulations;
_initializationState = InitializationState.IsInitialized; // fully initialized
}
private void Initialize(Uri typefaceSource, StyleSimulations styleSimulations)
{
ArgumentNullException.ThrowIfNull(typefaceSource);
if (!typefaceSource.IsAbsoluteUri)
throw new ArgumentException(SR.UriNotAbsolute, nameof(typefaceSource));
// remember the original Uri that contains face index
_originalUri = typefaceSource;
// split the Uri into the font source Uri and face index
Uri fontSourceUri;
int faceIndex;
Util.SplitFontFaceIndex(typefaceSource, out fontSourceUri, out faceIndex);
if ( styleSimulations != StyleSimulations.None
&& styleSimulations != StyleSimulations.ItalicSimulation
&& styleSimulations != StyleSimulations.BoldSimulation
&& styleSimulations != StyleSimulations.BoldItalicSimulation)
{
throw new InvalidEnumArgumentException("styleSimulations", (int)styleSimulations, typeof(StyleSimulations));
}
_styleSimulations = styleSimulations;View on GitHub (pinned to 81131a70a4)