dotnet/runtime · error · Error

URLSearchParams is supported

Error message

URLSearchParams is supported

What it means

withApplicationArgumentsFromQuery() also requires globalThis.URLSearchParams. If it is undefined the loader throws. NOTE: the message 'URLSearchParams is supported' is misleading — it is thrown precisely when URLSearchParams is NOT available, and reads like a positive assertion. Treat it as a missing-polyfill error, not a feature statement.

Source

Thrown at src/native/libs/Common/JavaScript/loader/host-builder.ts:75

    withDebugging(level: number): DotnetHostBuilder {
        mergeLoaderConfig({
            debugLevel: level
        });
        return this;
    }
    withMainAssembly(mainAssemblyName: string): DotnetHostBuilder {
        mergeLoaderConfig({
            mainAssemblyName: mainAssemblyName
        });
        return this;
    }
    withApplicationArgumentsFromQuery(): DotnetHostBuilder {
        if (!globalThis.window) {
            throw new Error("Missing window to the query parameters from");
        }

        if (typeof globalThis.URLSearchParams === "undefined") {
            throw new Error("URLSearchParams is supported");
        }

        const params = new URLSearchParams(globalThis.window.location.search);
        const values = params.getAll("arg");
        return this.withApplicationArguments(...values);
    }
    withApplicationEnvironment(applicationEnvironment?: string): DotnetHostBuilder {
        mergeLoaderConfig({
            applicationEnvironment: applicationEnvironment
        });
        return this;
    }
    withApplicationCulture(applicationCulture?: string): DotnetHostBuilder {
        mergeLoaderConfig({
            applicationCulture: applicationCulture
        });
        return this;
    }

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Provide a URLSearchParams polyfill before calling withApplicationArgumentsFromQuery (e.g. via core-js or url-search-params-polyfill).
  2. Upgrade the host engine to one with native URLSearchParams (all modern browsers and Node ≥ 10).
  3. Skip withApplicationArgumentsFromQuery and pass args directly via withApplicationArguments().

Example fix

// before
builder.withApplicationArgumentsFromQuery(); // throws on old engine

// after — polyfill first
if (typeof globalThis.URLSearchParams === 'undefined') {
  globalThis.URLSearchParams = (await import('url-search-params-polyfill')).default;
}
builder.withApplicationArgumentsFromQuery();
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof globalThis.URLSearchParams === 'undefined') {
  throw new Error('URLSearchParams missing — install a polyfill or upgrade the JS engine');
}

Type guard

function supportsUrlSearchParams(g: any): g is { URLSearchParams: typeof URLSearchParams } {
  return typeof g?.URLSearchParams === 'function';
}

Prevention

When it happens

Trigger: Running in an ancient/embedded JS engine that lacks URLSearchParams (very old browsers, minimal embedded JS shells). Combined with [74]: this guard is reached only when window exists but URLSearchParams does not.

Common situations: Legacy embedded WebView; a custom JS shell used for testing that does not implement URLSearchParams; very old Safari/IE; an environment that polyfilled window but not URLSearchParams.

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/fda1b493d7abdbea. Report an issue: GitHub.