dotnet/runtime · error · Error
args must be an object, but got
Error message
args must be an object, but got ${JSON.stringify(args)} What it means
Thrown by `mono_wasm_raise_debug_event` when the optional `args` argument is present but not an object. The default `{}` is fine; passing a primitive (e.g. an array or string) violates the contract that args is a key/value bag serialised as JSON alongside the event.
Solutions
- Omit `args` (or pass `{}`) when there are no extra parameters.
- If you have positional data, wrap it: `{ params: [...] }`.
- Ensure helper builders return `{}` rather than `null` for the no-args case.
Example fix
// before: array passed as args
mono_wasm_raise_debug_event(ev, ['a', 'b']); // throws
// after: wrap positional data in an object
mono_wasm_raise_debug_event(ev, { params: ['a', 'b'] }); Defensive patterns
Strategy: type-guard
Validate before calling
function raiseDebugEventSafe (event, args) {
const safeArgs = args === undefined ? {} : args;
if (safeArgs === null || typeof safeArgs !== 'object') {
throw new TypeError('args must be an object');
}
return mono_wasm_raise_debug_event(event, safeArgs);
} Type guard
function isArgsBag (v: unknown): v is Record<string, unknown> {
return v !== null && typeof v === 'object' && !Array.isArray(v);
} Prevention
- Default `args` to `{}` at the call site; never pass `null`.
- Wrap positional payloads in an object: `{ params: [...] }`.
- Type the parameter as `Record<string, unknown>` to forbid arrays.
When it happens
Trigger: Calling `mono_wasm_raise_debug_event(event, args)` (debug.ts:137) where `args` is a string, number, array, null, or boolean. Most commonly the caller passes a positional array of values, or passes `null` thinking it means 'no args'.
Common situations: Refactoring that changed args from object to array; passing the result of a function that returns null on empty; misunderstanding that `null` is not an object (typeof null === 'object' is true, but here null still triggers because the runtime asserts the value before that quirk only when args !== undefined — note the check is `typeof args !== 'object'`, which lets null through, so the realistic trigger is arrays/strings/numbers/booleans).
Related errors
- event.eventName is a required parameter, in event
- event must be an object, but got
- "arguments" should be an array, but was
- Argument to stringToInternedMonoStringRoot must be a string…
- capacity >= 1
AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10).
Data as JSON: /api/errors/62a2410f8e943cee.
Report an issue: GitHub.
Appendix: source
Thrown at src/mono/browser/runtime/debug.ts:138
}
export function mono_wasm_change_debugger_log_level (level: number): void {
forceThreadMemoryViewRefresh();
cwraps.mono_wasm_change_debugger_log_level(level);
}
/**
* Raises an event for the debug proxy
*/
export function mono_wasm_raise_debug_event (event: WasmEvent, args = {}): void {
if (typeof event !== "object")
throw new Error(`event must be an object, but got ${JSON.stringify(event)}`);
if (event.eventName === undefined)
throw new Error(`event.eventName is a required parameter, in event: ${JSON.stringify(event)}`);
if (typeof args !== "object")
throw new Error(`args must be an object, but got ${JSON.stringify(args)}`);
// eslint-disable-next-line no-console
console.debug("mono_wasm_debug_event_raised:aef14bca-5519-4dfe-b35a-f867abc123ae", JSON.stringify(event), JSON.stringify(args));
}
export function mono_wasm_wait_for_debugger (): Promise<void> {
return new Promise<void>((resolve) => {
const interval = setInterval(() => {
if (runtimeHelpers.waitForDebugger != 1) {
return;
}
clearInterval(interval);
resolve();
}, 100);
});
}
export function mono_wasm_debugger_attached (): void {View on GitHub (pinned to 60108ba66e)