dotnet/runtime · critical · Error

Expected internals to have RuntimeAPI

Error message

Expected internals to have RuntimeAPI

What it means

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.

Source

Thrown at src/native/libs/System.Runtime.InteropServices.JavaScript.Native/native/index.ts:39

}

export function SystemInteropJS_ResolveOrRejectPromise(args: JSMarshalerArguments): void {
    _ems_.dotnetRuntimeExports.resolveOrRejectPromise(args);
}

export function SystemInteropJS_CancelPromise(taskHolderGCHandle: GCHandle): void {
    _ems_.dotnetRuntimeExports.cancelPromise(taskHolderGCHandle);
}

export function SystemInteropJS_InvokeJSFunction(functionJSSHandle: JSHandle, args: JSMarshalerArguments): void {
    _ems_.dotnetRuntimeExports.invokeJSFunction(functionJSSHandle, args);
}

export const gitHash = GitHash;
export function dotnetInitializeModule(internals: InternalExchange): void {
    if (!Array.isArray(internals)) throw new Error("Expected internals to be an array");
    const runtimeApi = internals[InternalExchangeIndex.RuntimeAPI];
    if (typeof runtimeApi !== "object") throw new Error("Expected internals to have RuntimeAPI");

    if (runtimeApi.runtimeBuildInfo.gitHash && runtimeApi.runtimeBuildInfo.gitHash !== _ems_.DOTNET_INTEROP.gitHash) {
        throw new Error(`Mismatched git hashes between loader and runtime. Loader: ${runtimeApi.runtimeBuildInfo.gitHash}, DOTNET_INTEROP: ${_ems_.DOTNET_INTEROP.gitHash}`);
    }

    internals[InternalExchangeIndex.InteropJavaScriptExportsTable] = interopJavaScriptExportsToTable({
        SystemInteropJS_GetManagedStackTrace: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_GetManagedStackTrace(args),
        SystemInteropJS_CallDelegate: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_CallDelegate(args),
        SystemInteropJS_CompleteTask: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_CompleteTask(args),
        SystemInteropJS_ReleaseJSOwnedObjectByGCHandle: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_ReleaseJSOwnedObjectByGCHandle(args),
        SystemInteropJS_BindAssemblyExports: (args: JSMarshalerArguments) => _ems_._SystemInteropJS_BindAssemblyExports(args),
        SystemInteropJS_CallJSExport: (methodHandle: CSFnHandle, args: JSMarshalerArguments) => _ems_._SystemInteropJS_CallJSExport(methodHandle, args),
    });
    function interopJavaScriptExportsToTable(map: InteropJavaScriptExports): InteropJavaScriptExportsTable {
        // keep in sync with interopJavaScriptExportsFromTable()
        return [
            map.SystemInteropJS_GetManagedStackTrace,
            map.SystemInteropJS_CallDelegate,

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Re-fetch all runtime artifacts (dotnet.js, dotnet.runtime.js, dotnet.native.js) from one matching build.
  2. Clear browser cache / CDN edge cache and reload.
  3. If bundling, ensure the runtime API injection step runs before dotnetInitializeModule is called.
Defensive patterns

Strategy: validation

Validate before calling

function assertInternalsShape(internals: unknown[]) {
    const runtimeApi = internals[/* RuntimeAPI index */ 0];
    if (typeof runtimeApi !== "object" || runtimeApi === null) {
        throw new TypeError("Loader/runtime mismatch: internals[RuntimeAPI] missing");
    }
}

Type guard

const hasRuntimeApi = (internals: unknown[]): boolean =>
    Array.isArray(internals) && typeof internals[0] === "object" && internals[0] !== null;

Prevention

When it happens

Trigger: 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.

Common situations: Loader/runtime version mismatch; partial copy of runtime files; a bundler that reordered or dropped the runtime API injection.

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/4a849f968febec8f. Report an issue: GitHub.