dotnet/runtime · error · Error

"arguments" should be an array, but was

Error message

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

What it means

Thrown by `mono_wasm_call_function_on` when `request.arguments` is present but is not an array. The CDP-style `Runtime.callFunctionOn` contract requires `arguments` to be an array of `{ value }` entries; an object or single value is rejected.

Solutions

  1. Always pass `arguments` as an array, even for a single argument: `[{ value: x }]`.
  2. Omit `arguments` (or set to `undefined`) when calling with zero arguments.
  3. Add a type assertion or runtime check at the call site.

Example fix

// before: single object instead of array
mono_wasm_call_function_on({ objectId, functionDeclaration: 'fn', arguments: { value: 1 } }); // throws

// after: wrap in an array
mono_wasm_call_function_on({ objectId, functionDeclaration: 'fn', arguments: [{ value: 1 }] });
Defensive patterns

Strategy: type-guard

Validate before calling

function callFunctionOnSafe (request) {
  if (request.arguments !== undefined && !Array.isArray(request.arguments)) {
    throw new TypeError('request.arguments must be an array');
  }
  return mono_wasm_call_function_on(request);
}

Type guard

function isArgumentsArray (v: unknown): v is Array<{ value: unknown }> {
  return Array.isArray(v) && v.every(a => a !== null && typeof a === 'object' && 'value' in a);
}

Prevention

When it happens

Trigger: Calling `mono_wasm_call_function_on(request)` (debug.ts:224) with `request.arguments` set to an object, a string, or a single `{value}` instead of a list. Typical when a caller builds the request from a single argument without wrapping it in `[ ]`.

Common situations: Translating a DevTools Protocol payload incorrectly; reusing a request template and assigning a scalar to `arguments`; off-by-one in spreading arguments.

Related errors


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

Appendix: 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 60108ba66e)