{"record":{"id":"f65f52c10f723e03","repo":"dotnet/runtime","slug":"expected-runtimeoptions-to-be-an-array-of-strings","errorCode":null,"errorMessage":"Expected runtimeOptions to be an array of strings","messagePattern":"Expected runtimeOptions to be an array of strings","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/startup.ts","lineNumber":381,"sourceCode":"                mono_log_error(\"onDotnetReady () failed\", err);\n                throw err;\n            }\n        }\n    } catch (err: any) {\n        mono_log_error(\"mono_wasm_after_user_runtime_initialized () failed\", err);\n        throw err;\n    }\n}\n\n// Set environment variable NAME to VALUE\n// Should be called before mono_load_runtime_and_bcl () in most cases\nexport function mono_wasm_setenv (name: string, value: string): void {\n    cwraps.mono_wasm_setenv(name, value);\n}\n\nexport function mono_wasm_set_runtime_options (options: string[]): void {\n    if (!Array.isArray(options))\n        throw new Error(\"Expected runtimeOptions to be an array of strings\");\n\n    const argv = malloc(options.length * 4);\n    let aindex = 0;\n    for (let i = 0; i < options.length; ++i) {\n        const option = options[i];\n        if (typeof (option) !== \"string\")\n            throw new Error(\"Expected runtimeOptions to be an array of strings\");\n        Module.setValue(<any>argv + (aindex * 4), cwraps.mono_wasm_strdup(option), \"i32\");\n        aindex += 1;\n    }\n    cwraps.mono_wasm_parse_runtime_options(options.length, argv);\n}\n\nasync function instantiate_wasm_module (\n    imports: WebAssembly.Imports,\n    successCallback: InstantiateWasmSuccessCallback,\n): Promise<void> {\n    // this is called so early that even Module exports like addRunDependency don't exist yet","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/startup.ts#L363-L399","documentation":"Thrown by mono_wasm_set_runtime_options when the options argument fails Array.isArray. The runtime-options setter expects an array of strings (each forwarded to mono_wasm_parse_runtime_options); any non-array (object, string, number, null, undefined) is rejected before allocation.","triggerScenarios":"Calling mono_wasm_set_runtime_options('--gcserver') (a single string), mono_wasm_set_runtime_options(null), or passing an options object instead of an array. The check on line 380-381 fires immediately.","commonSituations":"Passing a single CLI-style string instead of ['--gcserver']; passing the raw config.runtimeOptions when it is undefined or an object; migrating from an API that accepted a comma-separated string.","solutions":["Always pass a string array: mono_wasm_set_runtime_options(['--gcserver', '--tiered']).","If your options may be a single string, wrap it: Array.isArray(opts) ? opts : opts ? [opts] : [].","Set config.runtimeOptions as an array in the runtime config object consumed by start_runtime."],"exampleFix":"// before\nmono_wasm_set_runtime_options('--gcserver');\n// after\nmono_wasm_set_runtime_options(['--gcserver']);","handlingStrategy":"type-guard","validationCode":"function setRuntimeOptionsSafe(opts: unknown) {\n  const arr = Array.isArray(opts) ? opts : opts == null ? [] : [opts];\n  mono_wasm_set_runtime_options(arr.filter((o): o is string => typeof o === 'string'));\n}","typeGuard":"function isStringArray(a: unknown): a is string[] {\n  return Array.isArray(a) && a.every(o => typeof o === 'string');\n}","tryCatchPattern":null,"preventionTips":["Type config.runtimeOptions as string[] at the boundary.","Wrap single-string usage into an array at the call site.","Coerce or filter before forwarding to the runtime API."],"tags":["startup","validation","argument-error","runtime-options","typescript"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}