dotnet/runtime · error · Error
event must be an object, but got
Error message
event must be an object, but got ${JSON.stringify(event)} What it means
Thrown by `mono_wasm_raise_debug_event` when its first argument is not an object. The function exists to forward structured debugger events to the BrowserDebugProxy via a console.debug magic line, and it requires an object payload to serialise via JSON. Primitives (string/number/boolean/undefined/null) are rejected because the protocol cannot represent them as an event envelope.
Solutions
- Pass `event` as an object literal that includes `eventName`, e.g. `mono_wasm_raise_debug_event({ eventName: 'X', ... }, args)`.
- If you have a serialized event, `JSON.parse` it before calling.
- Add a unit test asserting `typeof event === 'object' && event !== null` at the call site.
Example fix
// before: passed a string
mono_wasm_raise_debug_event('ScriptCompiled', {}); // throws
// after: pass an object
mono_wasm_raise_debug_event({ eventName: 'ScriptCompiled' }, {}); Defensive patterns
Strategy: type-guard
Validate before calling
function raiseDebugEventSafe (event, args) {
if (event === null || typeof event !== 'object') {
throw new TypeError('event must be a non-null object');
}
return mono_wasm_raise_debug_event(event, args);
} Type guard
function isDebugEvent (v: unknown): v is object {
return v !== null && typeof v === 'object';
} Prevention
- Build event payloads with a typed factory that returns `object`.
- If you hold the event as a serialized string, `JSON.parse` it first.
- Add a lint rule or unit test asserting the event argument is an object literal.
When it happens
Trigger: Calling `mono_wasm_raise_debug_event(event, args)` (debug.ts:130) with `event` being a string, number, boolean, null, or undefined. Usually a caller passed the event name as a string instead of wrapping it in an object, or passed `undefined` by mistake.
Common situations: Custom instrumentation code calling the API with the wrong shape; refactoring that lost the object wrapper; passing a serialized JSON string instead of an object.
Related errors
- args must be an object, but got
- event.eventName is a required parameter, in event
- "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/213466d04d2cc81d.
Report an issue: GitHub.
Appendix: source
Thrown at src/mono/browser/runtime/debug.ts:132
forceThreadMemoryViewRefresh();
}
export function mono_wasm_detach_debugger (): void {
forceThreadMemoryViewRefresh();
cwraps.mono_wasm_set_is_debugger_attached(false);
}
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);View on GitHub (pinned to 60108ba66e)