dotnet/runtime · critical · Error

Expected internals to be an array

Error message

Expected internals to be an array

What it means

The System.Native.Browser BrowserUtils module's dotnetInitializeModule asserts internals is an array before reading any slot. BrowserUtils provides heap accessors, string marshaling, and scheduling helpers that are wired into the exchange array, so a non-array breaks that contract immediately.

Source

Thrown at src/native/libs/System.Native.Browser/utils/index.ts:26

import {
    setHeapB32, setHeapB8, setHeapU8, setHeapU16, setHeapU32, setHeapI8, setHeapI16, setHeapI32, setHeapI52, setHeapU52, setHeapI64Big, setHeapF32, setHeapF64,
    getHeapB32, getHeapB8, getHeapU8, getHeapU16, getHeapU32, getHeapI8, getHeapI16, getHeapI32, getHeapI52, getHeapU52, getHeapI64Big, getHeapF32, getHeapF64,
    localHeapViewI8, localHeapViewI16, localHeapViewI32, localHeapViewI64Big, localHeapViewU8, localHeapViewU16, localHeapViewU32, localHeapViewF32, localHeapViewF64,
    zeroRegion,
    arrayBufferNeedsCopy,
    viewOrCopy,
} from "./memory";
import { stringsInit, stringToUTF16, stringToUTF16Ptr, stringToUTF8, stringToUTF8Ptr, utf16ToString, utf8ToStringRelaxed } from "./strings";
import { abortPosix, getExitStatus } from "./host";
import { dotnetUpdateInternals, dotnetUpdateInternalsSubscriber } from "../utils/cross-module";
import { initPolyfills } from "../utils/polyfills";
import { registerRuntime } from "./runtime-list";
import { registerCDAC } from "./cdac";
import { abortBackgroundTimers, runBackgroundTimers } from "./scheduling";

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 !== GitHash) {
        throw new Error(`Mismatched git hashes between loader and runtime. Loader: ${runtimeApi.runtimeBuildInfo.gitHash}, BrowserUtils: ${GitHash}`);
    }

    initPolyfills();
    stringsInit();
    registerRuntime(runtimeApi);
    registerCDAC(runtimeApi);

    if (!Array.isArray(internals)) throw new Error("Expected internals to be an array");
    const runtimeApiLocal: Partial<RuntimeAPI> = {
        setHeapB32, setHeapB8, setHeapU8, setHeapU16, setHeapU32, setHeapI8, setHeapI16, setHeapI32, setHeapI52, setHeapU52, setHeapI64Big, setHeapF32, setHeapF64,
        getHeapB32, getHeapB8, getHeapU8, getHeapU16, getHeapU32, getHeapI8, getHeapI16, getHeapI32, getHeapI52, getHeapU52, getHeapI64Big, getHeapF32, getHeapF64,
        localHeapViewI8, localHeapViewI16, localHeapViewI32, localHeapViewI64Big, localHeapViewU8, localHeapViewU16, localHeapViewU32, localHeapViewF32, localHeapViewF64,
    };

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Forward the exact internals array produced by the runtime loader, unwrapped.
  2. Rebuild with a matching SDK so loader and utils bundles agree on the InternalExchange array contract.
  3. Clear cached/stale bundles and redeploy all dotnet files together.

Example fix

// before
dotnetInitializeModule({ internals: arr })

// after
dotnetInitializeModule(arr)
Defensive patterns

Strategy: type-guard

Validate before calling

if (!Array.isArray(internals)) throw new TypeError("internals must be an array");
dotnetInitializeModule(internals);

Type guard

const isInternalExchange = (x): x is any[] => Array.isArray(x);

Prevention

When it happens

Trigger: dotnetInitializeModule for the utils module receives a non-array (object/undefined/null) because the host forwarded a different exchange shape than the positional array.

Common situations: Mismatched loader/utils bundle versions; a custom host that wraps internals in an object; a deploy that pulled only some of the dotnet bundles.

Related errors


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