HandyOrg/HandyControl · error · ArgumentException

The URI must be absolute.

Error message

The URI must be absolute.

What it means

Verify.UriIsAbsolute is a debug-style argument validator in the Microsoft.Windows.Shell helper library. It asserts that the Uri parameter passed to an API is an absolute URI (has a scheme such as 'pack:' or 'http:'). It first checks for null, then throws ArgumentException when Uri.IsAbsoluteUri is false.

Solutions

  1. Ensure the Uri is created with UriKind.Absolute and includes a scheme, e.g. new Uri("pack://application:,,,/Images/foo.png")
  2. If starting from a relative path, resolve it against a base Uri: new Uri(baseUri, relativePath)
  3. Null-check and validate uri.IsAbsoluteUri before calling the library API

Example fix

// before
var uri = new Uri("images/foo.png", UriKind.Relative);
ChromeApi.SetIcon(uri);
// after
var uri = new Uri("pack://application:,,,/images/foo.png", UriKind.Absolute);
ChromeApi.SetIcon(uri);
Defensive patterns

Strategy: validation

Validate before calling

if (uri == null || !uri.IsAbsoluteUri) throw new ArgumentException("An absolute URI is required", nameof(uri));

Type guard

bool IsAbsolute(Uri u) => u != null && u.IsAbsoluteUri;

Try / catch

try { api.Call(uri); } catch (ArgumentException ex) when (ex.Message.Contains("absolute")) { /* handle relative URI case */ }

Prevention

When it happens

Trigger: Calling any API in the Microsoft.Windows.Shell/Standard utility layer that routes through Verify.UriIsAbsolute with a relative Uri (e.g. new Uri("images/foo.png", UriKind.Relative)) or a null Uri.

Common situations: Developers construct URIs from strings that lack a scheme, or use UriKind.Relative by mistake when an absolute URI (usually a pack:// application resource URI) is expected.

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


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/9979ea4f07bfe0c7. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs:170

            if (actual == null || actual.Equals(notExpected))
            {
                throw new ArgumentException(message, parameterName);
            }
        }
        else if (notExpected.Equals(actual))
        {
            throw new ArgumentException(message, parameterName);
        }
    }

    [DebuggerStepThrough]
    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    public static void UriIsAbsolute(Uri uri, string parameterName)
    {
        Verify.IsNotNull<Uri>(uri, parameterName);
        if (!uri.IsAbsoluteUri)
        {
            throw new ArgumentException("The URI must be absolute.", parameterName);
        }
    }

    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    [DebuggerStepThrough]
    public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)
    {
        if (value < lowerBoundInclusive || value >= upperBoundExclusive)
        {
            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The integer value must be bounded with [{0}, {1})", new object[]
            {
                lowerBoundInclusive,
                upperBoundExclusive
            }), parameterName);
        }
    }

    [DebuggerStepThrough]

View on GitHub (pinned to 2c0875ebd6)