{"record":{"id":"4a849f968febec8f","repo":"dotnet/runtime","slug":"expected-internals-to-have-runtimeapi-4a849f","errorCode":null,"errorMessage":"Expected internals to have RuntimeAPI","messagePattern":"Expected internals to have RuntimeAPI","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/native/libs/System.Runtime.InteropServices.JavaScript.Native/native/index.ts","lineNumber":39,"sourceCode":"}\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 [\n            map.SystemInteropJS_GetManagedStackTrace,\n            map.SystemInteropJS_CallDelegate,","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/native/index.ts#L21-L57","documentation":"Thrown by dotnetInitializeModule after confirming internals is an array, when internals[InternalExchangeIndex.RuntimeAPI] is not an object. The RuntimeAPI slot must carry the runtime's API surface (build info, heap views, helpers); its absence means the loader did not provide the runtime API the native module needs.","triggerScenarios":"The loader initializes internals with the wrong indices, leaves the RuntimeAPI slot empty, or supplies a stale/partial API object from an incompatible loader build.","commonSituations":"Loader/runtime version mismatch; partial copy of runtime files; a bundler that reordered or dropped the runtime API injection.","solutions":["Re-fetch all runtime artifacts (dotnet.js, dotnet.runtime.js, dotnet.native.js) from one matching build.","Clear browser cache / CDN edge cache and reload.","If bundling, ensure the runtime API injection step runs before dotnetInitializeModule is called."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function assertInternalsShape(internals: unknown[]) {\n    const runtimeApi = internals[/* RuntimeAPI index */ 0];\n    if (typeof runtimeApi !== \"object\" || runtimeApi === null) {\n        throw new TypeError(\"Loader/runtime mismatch: internals[RuntimeAPI] missing\");\n    }\n}","typeGuard":"const hasRuntimeApi = (internals: unknown[]): boolean =>\n    Array.isArray(internals) && typeof internals[0] === \"object\" && internals[0] !== null;","tryCatchPattern":null,"preventionTips":["Use one coherent set of runtime files per build.","Clear caches/CDN edges when upgrading the SDK.","Verify bundlers preserve the runtime API injection order."],"tags":["initialization","loader","runtime-api","version-mismatch","internal"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}