{"record":{"id":"c786d8d97532a47d","repo":"dotnet/runtime","slug":"expected-internals-to-be-an-array-c786d8","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.Runtime.InteropServices.JavaScript.Native/interop/index.ts","lineNumber":31,"sourceCode":"} from \"./invoke-js\";\nimport { bindCsFunction, getAssemblyExports } from \"./invoke-cs\";\nimport { initializeMarshalersToJs, resolveOrRejectPromise } from \"./marshal-to-js\";\nimport { initializeMarshalersToCs } from \"./marshal-to-cs\";\nimport { forceDisposeProxies, releaseCSOwnedObject } from \"./gc-handles\";\nimport { cancelPromise } from \"./cancelable-promise\";\nimport { loadLazyAssembly, loadSatelliteAssemblies } from \"./lazy\";\nimport { jsInteropState } from \"./marshal\";\nimport { initializeScheduling, abortInteropTimers } from \"./scheduling\";\nimport { wsAbort, wsClose, wsCreate, wsGetState, wsOpen, wsReceive, wsSend } from \"./web-socket\";\nimport {\n    httpSupportsStreamingRequest, httpSupportsStreamingResponse, httpCreateController, httpGetResponseType,\n    httpGetResponseStatus, httpAbort, httpTransformStreamWrite, httpTransformStreamClose, httpFetch,\n    httpFetchStream, httpFetchBytes, httpGetResponseHeaderNames, httpGetResponseHeaderValues, httpGetResponseBytes,\n    httpGetResponseLength, httpGetStreamedResponseBytes,\n} from \"./http\";\n\nexport function dotnetInitializeModule(internals: InternalExchange): void {\n    if (!Array.isArray(internals)) throw new Error(\"Expected internals to be an array\");\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 !== GitHash) {\n        throw new Error(`Mismatched git hashes between loader and runtime. Loader: ${runtimeApi.runtimeBuildInfo.gitHash}, Runtime: ${GitHash}`);\n    }\n\n    const runtimeApiLocal: Partial<RuntimeAPI> = {\n        getAssemblyExports,\n        setModuleImports,\n    };\n    Object.assign(runtimeApi, runtimeApiLocal);\n    Object.assign(runtimeApi.INTERNAL, {\n        hasProperty,\n        getTypeOfProperty,\n        getProperty,\n        setProperty,\n        getGlobalThis,","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/index.ts#L13-L49","documentation":"The System.Runtime.InteropServices.JavaScript interop module's dotnetInitializeModule asserts internals is an array. This module wires up JSImport/JSCall marshaling, lazy assembly loading, websockets, and HTTP, all of which read slots from the positional InternalExchange array, so a non-array breaks the contract before any interop can be set up.","triggerScenarios":"dotnetInitializeModule for the interop module receives a non-array (object/undefined/null) because the host forwarded a wrapped or differently-shaped exchange instead of the raw array.","commonSituations":"Mismatched loader/interop bundle versions; a custom host wrapping internals in an object; partial deploy of dotnet bundles.","solutions":["Forward the exact internals array produced by the runtime loader, unwrapped.","Rebuild with a matching SDK so the loader and interop bundles agree on the InternalExchange array contract.","Clear cached/stale bundles and redeploy all dotnet files together."],"exampleFix":"// before\ndotnetInitializeModule({ internals: arr })\n\n// after\ndotnetInitializeModule(arr)","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":["Forward the internals array from the runtime loader unwrapped.","Rebuild loader and interop bundles together from one SDK."],"tags":["initialization","internals","runtime-interop"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}