{"record":{"id":"d24ab1bca1fe8147","repo":"dotnet/runtime","slug":"expected-internals-to-be-an-array-d24ab1","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/native/index.ts","lineNumber":37,"sourceCode":"export function SystemInteropJS_ReleaseCSOwnedObject(jsHandle: JSHandle): void {\n    _ems_.dotnetRuntimeExports.releaseCSOwnedObject(jsHandle);\n}\n\nexport function SystemInteropJS_ResolveOrRejectPromise(args: JSMarshalerArguments): void {\n    _ems_.dotnetRuntimeExports.resolveOrRejectPromise(args);\n}\n\nexport function SystemInteropJS_CancelPromise(taskHolderGCHandle: GCHandle): void {\n    _ems_.dotnetRuntimeExports.cancelPromise(taskHolderGCHandle);\n}\n\nexport function SystemInteropJS_InvokeJSFunction(functionJSSHandle: JSHandle, args: JSMarshalerArguments): void {\n    _ems_.dotnetRuntimeExports.invokeJSFunction(functionJSSHandle, args);\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    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_INTEROP.gitHash) {\n        throw new Error(`Mismatched git hashes between loader and runtime. Loader: ${runtimeApi.runtimeBuildInfo.gitHash}, DOTNET_INTEROP: ${_ems_.DOTNET_INTEROP.gitHash}`);\n    }\n\n    internals[InternalExchangeIndex.InteropJavaScriptExportsTable] = interopJavaScriptExportsToTable({\n        SystemInteropJS_GetManagedStackTrace: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_GetManagedStackTrace(args),\n        SystemInteropJS_CallDelegate: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_CallDelegate(args),\n        SystemInteropJS_CompleteTask: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_CompleteTask(args),\n        SystemInteropJS_ReleaseJSOwnedObjectByGCHandle: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_ReleaseJSOwnedObjectByGCHandle(args),\n        SystemInteropJS_BindAssemblyExports: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_BindAssemblyExports(args),\n        SystemInteropJS_CallJSExport: (methodHandle: CSFnHandle, args: JSMarshalerArguments) => _ems_._SystemInteropJS_CallJSExport(methodHandle, args),\n    });\n    function interopJavaScriptExportsToTable(map: InteropJavaScriptExports): InteropJavaScriptExportsTable {\n        // keep in sync with interopJavaScriptExportsFromTable()\n        return [","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/native/index.ts#L19-L55","documentation":"Thrown by dotnetInitializeModule when the `internals` argument passed to the runtime initializer is not an Array. The runtime expects internals to be a positional array indexed by InternalExchangeIndex (RuntimeAPI, export tables, etc.); a non-array indicates the loader and the native module are talking different protocols.","triggerScenarios":"The loader hands the native module an object/record instead of the indexed array, typically because of a version mismatch between the loader JS and the compiled runtime module, or a custom hosting setup that constructs internals incorrectly.","commonSituations":"Mixing dotnet.js / dotnet.runtime.js / dotnet.native.js from different SDK builds; a custom host that builds the internals object manually and gets the shape wrong.","solutions":["Use the matching set of runtime files from a single .NET SDK build (clean the output directory and republish).","If hosting manually, pass internals as an array with slots populated per InternalExchangeIndex.","Verify there is exactly one version of each runtime file on the page/server."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function assertInternalsShape(internals: unknown) {\n    if (!Array.isArray(internals)) {\n        throw new TypeError(\"Loader/runtime mismatch: internals must be an array\");\n    }\n}","typeGuard":"const isInternalsArray = (v: unknown): v is unknown[] => Array.isArray(v);","tryCatchPattern":null,"preventionTips":["Ship loader, runtime, and native files from a single matching build.","In custom hosts, build internals as a positional array per InternalExchangeIndex.","Pin runtime NuGet/package versions."],"tags":["initialization","loader","version-mismatch","internal"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}