dotnet/runtime · error · Error
URLSearchParams is supported
Error message
URLSearchParams is supported
What it means
Thrown by withApplicationArgumentsFromQuery() when globalThis.URLSearchParams is undefined. Despite the misleading message text ('URLSearchParams is supported'), the guard at line 181 fires when the API is NOT present, preventing the builder from parsing query-string arguments. This is a host-capability check that fails on very old browsers or non-browser JS runtimes that lack URLSearchParams. The .NET WASM loader needs it to read 'arg' query parameters from window.location.search.
Solutions
- If running in Node or a non-browser environment, avoid withApplicationArgumentsFromQuery() and use withApplicationArguments(...args) to pass args directly.
- Polyfill URLSearchParams before creating the runtime: if (typeof globalThis.URLSearchParams === 'undefined') { globalThis.URLSearchParams = require('url').URLSearchParams; }
- Upgrade to a modern browser that natively supports URLSearchParams (all evergreen browsers since 2019).
- Ensure the code runs in a context that has globalThis.window.location.search available.
Example fix
// before
const runtime = await dotnet
.withApplicationArgumentsFromQuery()
.create();
// after (pass args explicitly instead of relying on URL query string)
const runtime = await dotnet
.withApplicationArguments('--foo', 'bar')
.create(); Defensive patterns
Strategy: validation
Validate before calling
// Check before calling withApplicationArgumentsFromQuery
if (typeof globalThis.URLSearchParams === 'undefined' || !globalThis.window) {
// use direct args instead
dotnet.withApplicationArguments(...myArgs);
} else {
dotnet.withApplicationArgumentsFromQuery();
} Type guard
function supportsUrlSearchParams(): boolean {
return typeof globalThis.URLSearchParams !== 'undefined'
&& typeof globalThis.window !== 'undefined';
} Try / catch
try {
await dotnet.withApplicationArgumentsFromQuery().create();
} catch (e) {
if (e.message.includes('URLSearchParams')) {
// fallback: pass args directly
await dotnet.withApplicationArguments('--fallback-arg').create();
} else {
throw e;
}
} Prevention
- Always have a fallback path that uses withApplicationArguments() instead of relying on URL query strings.
- Polyfill URLSearchParams in non-browser test environments.
- Detect the environment (browser vs Node/worker) before choosing the arguments API.
When it happens
Trigger: Calling dotnet.withApplicationArgumentsFromQuery() in a JS runtime where globalThis.URLSearchParams is undefined (old browser, Node without polyfill, or a non-window worker context). The method also requires globalThis.window to exist.
Common situations: Running the .NET WASM runtime in a very old browser (pre-2019), in a Node.js test harness without a URLSearchParams polyfill, or in a service worker / web worker that has no window object. Developers testing locally in Node often hit this.
Related errors
- No fetch implementation available
- No fetch implementation available
- Please install `node-fetch` and `node-abort-controller` npm…
- URLSearchParams is supported
- Using node without crypto support. To enable current…
AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10).
Data as JSON: /api/errors/94eb8775da7ea828.
Report an issue: GitHub.
Appendix: source
Thrown at src/mono/browser/runtime/loader/run.ts:182
try {
deep_merge_config(monoConfig, {
mainAssemblyName
});
return this;
} catch (err) {
mono_exit(1, err);
throw err;
}
}
withApplicationArgumentsFromQuery (): DotnetHostBuilder {
try {
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);
} catch (err) {
mono_exit(1, err);
throw err;
}
}
withApplicationEnvironment (applicationEnvironment?: string): DotnetHostBuilder {
try {
deep_merge_config(monoConfig, {
applicationEnvironment,
});
return this;
} catch (err) {View on GitHub (pinned to 60108ba66e)