{"record":{"id":"54488b90c4fa45a6","repo":"dotnet/runtime","slug":"invalid-jsthreadblockingmode","errorCode":null,"errorMessage":"Invalid jsThreadBlockingMode","messagePattern":"Invalid jsThreadBlockingMode","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/managed-exports.ts","lineNumber":273,"sourceCode":"        const arg2 = get_arg(args, 3);\n        set_arg_intptr(arg1, mono_wasm_main_thread_ptr() as any);\n\n        // sync with JSHostImplementation.Types.cs\n        switch (jsThreadBlockingMode) {\n            case JSThreadBlockingMode.PreventSynchronousJSExport:\n                set_arg_i32(arg2, 0);\n                break;\n            case JSThreadBlockingMode.ThrowWhenBlockingWait:\n                set_arg_i32(arg2, 1);\n                break;\n            case JSThreadBlockingMode.WarnWhenBlockingWait:\n                set_arg_i32(arg2, 2);\n                break;\n            case JSThreadBlockingMode.DangerousAllowBlockingWait:\n                set_arg_i32(arg2, 100);\n                break;\n            default:\n                throw new Error(\"Invalid jsThreadBlockingMode\");\n        }\n\n        // this block is like invoke_sync_jsexport() but without assert_js_interop()\n        cwraps.mono_wasm_invoke_jsexport(managedExports.InstallMainSynchronizationContext!, args);\n        if (is_args_exception(args)) {\n            const exc = get_arg(args, 0);\n            throw marshal_exception_to_js(exc);\n        }\n        return get_arg_gc_handle(res) as any;\n    } catch (e) {\n        mono_log_error(\"install_main_synchronization_context failed\", e);\n        throw e;\n    }\n}\n\nexport function invoke_async_jsexport (managedTID: PThreadPtr, method: MonoMethod, args: JSMarshalerArguments, size: number): void {\n    assert_js_interop();\n    if (!WasmEnableThreads || runtimeHelpers.isManagedRunningOnCurrentThread) {","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/managed-exports.ts#L255-L291","documentation":"Thrown by install_main_synchronization_context() when the jsThreadBlockingMode argument does not match any of the four known enum values (PreventSynchronousJSExport, ThrowWhenBlockingWait, WarnWhenBlockingWait, DangerousAllowBlockingWait). The switch statement's default case fires. This is a configuration or programming error: an invalid string or number was passed where a JSThreadBlockingMode enum value is required.","triggerScenarios":"Calling install_main_synchronization_context() with an unrecognized jsThreadBlockingMode value, or configuring the runtime with a misspelled or non-enum jsThreadBlockingMode string in the config. Also triggers if the config is loaded from JSON with a typo in the mode name.","commonSituations":"Typo in config JSON (e.g., 'PreventSyncJSExport' instead of 'PreventSynchronousJSExport'). Passing a numeric value instead of the enum string. Passing undefined or null that slips through the switch. Version mismatch where an old config uses a mode name that was renamed.","solutions":["Use one of the four valid JSThreadBlockingMode string values: 'PreventSynchronousJSExport', 'ThrowWhenBlockingWait', 'WarnWhenBlockingWait', or 'DangerousAllowBlockingWait'.","Validate the config value before passing it: check against the known set.","If loading config from JSON, verify the spelling of the jsThreadBlockingMode field.","Leave jsThreadBlockingMode unset to use the default (PreventSynchronousJSExport) if you don't need a specific mode."],"exampleFix":"// before (typo in config)\nconst runtime = await dotnet\n  .withConfig({ config: { jsThreadBlockingMode: 'PreventSyncExport' } })\n  .create();\n\n// after (correct enum value)\nconst runtime = await dotnet\n  .withConfig({ config: { jsThreadBlockingMode: 'PreventSynchronousJSExport' } })\n  .create();","handlingStrategy":"validation","validationCode":"// Validate jsThreadBlockingMode before passing to config\nconst validModes = ['PreventSynchronousJSExport', 'ThrowWhenBlockingWait', 'WarnWhenBlockingWait', 'DangerousAllowBlockingWait'];\nif (config.jsThreadBlockingMode && !validModes.includes(config.jsThreadBlockingMode)) {\n  throw new Error(`Invalid jsThreadBlockingMode: ${config.jsThreadBlockingMode}. Must be one of: ${validModes.join(', ')}`);\n}","typeGuard":"function isValidJSThreadBlockingMode(mode: string): mode is 'PreventSynchronousJSExport' | 'ThrowWhenBlockingWait' | 'WarnWhenBlockingWait' | 'DangerousAllowBlockingWait' {\n  return ['PreventSynchronousJSExport', 'ThrowWhenBlockingWait', 'WarnWhenBlockingWait', 'DangerousAllowBlockingWait'].includes(mode);\n}","tryCatchPattern":null,"preventionTips":["Always use the JSThreadBlockingMode enum constants instead of raw strings.","Validate config values loaded from external JSON before passing to the runtime.","Omit jsThreadBlockingMode to use the safe default (PreventSynchronousJSExport)."],"tags":["configuration","threading","validation","enum"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}