{"record":{"id":"961d2db53790bdd0","repo":"dotnet/runtime","slug":"expected-internals-to-be-an-array-961d2d","errorCode":null,"errorMessage":"Expected internals to be an array","messagePattern":"Expected internals to be an array","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/native/libs/System.Native.Browser/native/index.ts","lineNumber":19,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nimport type { InternalExchange, NativeBrowserExports, NativeBrowserExportsTable } from \"../types\";\nimport { InternalExchangeIndex } from \"../types\";\n\nimport { _ems_ } from \"../../Common/JavaScript/ems-ambient\";\nimport GitHash from \"consts:gitHash\";\n\nexport { SystemJS_RandomBytes } from \"./crypto\";\nexport { SystemJS_GetLocaleInfo } from \"./globalization-locale\";\nexport { SystemJS_RejectMainPromise, SystemJS_ResolveMainPromise, SystemJS_MarkAsyncMain, SystemJS_ConsoleClear } from \"./main\";\nexport { SystemJS_ScheduleTimer, SystemJS_ScheduleBackgroundJob, SystemJS_ScheduleFinalization, SystemJS_ScheduleDiagnosticServer } from \"./scheduling\";\nexport { ds_rt_websocket_close, ds_rt_websocket_create, ds_rt_websocket_poll, ds_rt_websocket_recv, ds_rt_websocket_send, ds_rt_browser_performance_measure } from \"./diagnostics\";\n\n\nexport const gitHash = GitHash;\nexport function dotnetInitializeModule(internals: InternalExchange): void {\n    if (!Array.isArray(internals)) throw new Error(\"Expected internals to be an array\");\n\n    const runtimeApi = internals[InternalExchangeIndex.RuntimeAPI];\n    if (typeof runtimeApi !== \"object\") throw new Error(\"Expected internals to have RuntimeAPI\");\n\n    if (runtimeApi.runtimeBuildInfo.gitHash && runtimeApi.runtimeBuildInfo.gitHash !== _ems_.DOTNET.gitHash) {\n        throw new Error(`Mismatched git hashes between loader and runtime. Loader: ${runtimeApi.runtimeBuildInfo.gitHash}, DOTNET: ${_ems_.DOTNET.gitHash}`);\n    }\n\n    internals[InternalExchangeIndex.NativeBrowserExportsTable] = nativeBrowserExportsToTable({\n        getWasmMemory,\n        getWasmTable,\n        SystemJS_ScheduleDiagnosticServer: _ems_._SystemJS_ScheduleDiagnosticServer,\n        SystemJS_GetMethodName: (pMethodDesc: number) => _ems_._SystemJS_GetMethodName(pMethodDesc),\n    });\n    _ems_.dotnetUpdateInternals(internals, _ems_.dotnetUpdateInternalsSubscriber);\n\n    setupEmscripten();\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Native.Browser/native/index.ts#L1-L37","documentation":"The System.Native.Browser native module's dotnetInitializeModule first asserts that internals is an array. The runtime exchanges data with native libraries through a positional InternalExchange array, so a non-array means the loader/native contract is broken before any export can be registered.","triggerScenarios":"dotnetInitializeModule receives a non-array (an object, undefined, or null) — a loader passing a different exchange shape than the positional array the native module expects.","commonSituations":"Mismatched loader/native bundle versions; a hand-written host that wraps internals in an object instead of forwarding the raw array; a corrupted/renamed bundle.","solutions":["Rebuild with a matching SDK so the loader and native bundles agree on the InternalExchange array contract.","If hosting manually, forward the exact internals array produced by the runtime loader verbatim, not a wrapped object.","Clear cached stale bundles and redeploy."],"exampleFix":"// before\ndotnetInitializeModule({ runtime: runtimeApi }) // object, not array\n\n// after\ndotnetInitializeModule([runtimeApi, /* other slots */])","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(internals)) throw new TypeError(\"internals must be an array\");\ndotnetInitializeModule(internals);","typeGuard":"const isInternalExchange = (x): x is any[] => Array.isArray(x);","tryCatchPattern":null,"preventionTips":["Never wrap the internals array; forward it verbatim from the runtime loader.","Pin all dotnet bundles to one build/SDK version."],"tags":["initialization","internals","runtime-interop"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}