dotnet/runtime · error · Error

"arguments" should be an array, but was ${request.arguments}

Error message

"arguments" should be an array, but was ${request.arguments}

What it means

Thrown by mono_wasm_call_function_on() in debug.ts when request.arguments is defined but is not an Array. This function implements the CDP Runtime.callFunctionOn against .NET objects: arguments must be an array of { value } entries (type CallArgs[]) so they can be JSON.stringify'd into the generated function body. Passing an object or single value instead of an array breaks the .map in the function body construction.

Source

Thrown at src/mono/browser/runtime/debug.ts:228

                        return prop.value;
                    },
                    set: function (newValue) {
                        mono_wasm_send_dbg_command_with_parms(prop.set.id, prop.set.commandSet, prop.set.command, prop.set.buffer, prop.set.length, prop.set.valtype, newValue); return true;
                    }
                }
            );
        } else {
            proxy[prop.name] = prop.value;
        }
    });
    return proxy;
}

export function mono_wasm_call_function_on (request: CallRequest): CFOResponse {
    forceThreadMemoryViewRefresh();

    if (request.arguments != undefined && !Array.isArray(request.arguments))
        throw new Error(`"arguments" should be an array, but was ${request.arguments}`);

    const objId = request.objectId;
    const details = request.details;
    let proxy: any = {};

    if (objId.startsWith("dotnet:cfo_res:")) {
        if (objId in _call_function_res_cache)
            proxy = _call_function_res_cache[objId];
        else
            throw new Error(`Unknown object id ${objId}`);
    } else {
        proxy = _create_proxy_from_object_id(objId, details);
    }

    const fn_args = request.arguments != undefined ? request.arguments.map(a => JSON.stringify(a.value)) : [];

    const fn_body_template = `const fn = ${request.functionDeclaration}; return fn.apply(proxy, [${fn_args}]);`;
    const fn_defn = new Function("proxy", fn_body_template);

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Send arguments as an array: request.arguments = [{ value: JSON.stringify(v) }, ...].
  2. If you have no arguments, set request.arguments = undefined (the check skips undefined).
  3. Validate with Array.isArray(request.arguments) before calling.

Example fix

// before
{ objectId, arguments: { value: '"42"' } }

// after
{ objectId, arguments: [{ value: '"42"' }] }
Defensive patterns

Strategy: validation

Validate before calling

function callFunctionOn(request: CallRequest) {
  if (request.arguments !== undefined && !Array.isArray(request.arguments)) {
    throw new TypeError('request.arguments must be an array of { value } or undefined');
  }
  return mono_wasm_call_function_on(request);
}

Type guard

function isValidCallArgs(a: unknown): a is Array<{ value: string }> | undefined {
  return a === undefined || (Array.isArray(a) && a.every(x => x != null && typeof x === 'object' && 'value' in x));
}

Try / catch

null

Prevention

When it happens

Trigger: The DevTools/CDP client sending arguments as an object ({0: ...}) or a single value rather than an array. A custom debugger integration building a CallRequest with request.arguments = someObject.

Common situations: A non-standard CDP client or test harness mis-serializing arguments. Forked debugger glue that constructs CallRequest manually and forgets the array wrapper.

Related errors


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