dotnet/wpf · error · ArgumentException
SR.UriNotAbsolute
Error message
SR.UriNotAbsolute
What it means
ColorContext's Initialize throws ArgumentException when the supplied profileUri is not an absolute URI. The context must be able to resolve and load the profile file/package part, which requires an absolute URI; relative URIs are rejected up front (after a null check).
Solutions
- Build an absolute URI: new Uri(new Uri(AppContext.BaseDirectory), relativePath) or use an absolute pack URI (pack://application:,,,/Profiles/x.icc).
- Specify UriKind.Absolute when constructing from a string with a full path.
- Guard with profileUri.IsAbsoluteUri before constructing the ColorContext and resolve relative paths first.
Example fix
// before
var ctx = new ColorContext(new Uri("Profiles/sRGB.icc")); // ArgumentException
// after
var abs = new Uri(new Uri(AppContext.BaseDirectory), "Profiles/sRGB.icc");
var ctx = new ColorContext(abs); Defensive patterns
Strategy: validation
Validate before calling
if (profileUri == null) throw new ArgumentNullException(nameof(profileUri));
if (!profileUri.IsAbsoluteUri) throw new ArgumentException("Profile URI must be absolute", nameof(profileUri)); Type guard
bool IsValidProfileUri(Uri u) => u is not null && u.IsAbsoluteUri;
Try / catch
try { var ctx = new ColorContext(profileUri); }
catch (ArgumentException ex) when (ex.ParamName == nameof(profileUri)) { profileUri = MakeAbsolute(profileUri); var ctx = new ColorContext(profileUri); } Prevention
- Always build profile URIs with UriKind.Absolute
- Convert config-relative paths against a known base URI early
- Use full pack:// URIs for resources embedded in assemblies
When it happens
Trigger: new ColorContext(new Uri("profiles/sRGB.icc")) or new ColorContext(new Uri(relativeString, UriKind.Relative)) — profileUri.IsAbsoluteUri is false at ColorContext.cs:487.
Common situations: Config files or code storing profile paths as relative paths; pack URIs built without the pack:// scheme; string-to-Uri conversion defaulting to RelativeKind.
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
- SR.AbsoluteUriOnly
- SR.Effect_SourceUriMustBeFileOrPack
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriRemote"…
- SR.NonPackSooAbsoluteUriNotAllowed
- UriMustBeAbsolute
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8de6358e12068129.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorContext.cs:487
return !(context1 == context2);
}
#endregion
#region Private Methods
/// <summary>
/// Loads color profile given by profileUri
/// </summary>
private void Initialize(Uri profileUri, bool isStandardProfileUriNotFromUser)
{
bool tryProfileFromResource = false;
ArgumentNullException.ThrowIfNull(profileUri);
if (!profileUri.IsAbsoluteUri)
{
throw new ArgumentException(SR.UriNotAbsolute, nameof(profileUri));
}
// Security: When loading XPS content, block color profile URIs that
// escape the current package to prevent SSRF. Standard system profiles
// (isStandardProfileUriNotFromUser == true) are always local file
// paths and are exempt from this check. Uses both ambient context
// and captured origin for defense-in-depth.
_xpsPackageOrigin = XpsLoadingContext.ActivePackageUri;
if (!isStandardProfileUriNotFromUser
&& !XpsLoadingContext.IsUriAllowedAgainstPackage(_xpsPackageOrigin, profileUri))
{
throw new FileFormatException(SR.Resource_XpsPackageBoundaryViolation);
}
_profileUri = profileUri;
_isProfileUriNotFromUser = isStandardProfileUriNotFromUser;
Stream profileStream = null;View on GitHub (pinned to 81131a70a4)