dotnet/runtime · critical · Error
Expected internals to be an array
Error message
Expected internals to be an array
What it means
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.
Source
Thrown at src/native/libs/System.Runtime.InteropServices.JavaScript.Native/native/index.ts:37
export function SystemInteropJS_ReleaseCSOwnedObject(jsHandle: JSHandle): void {
_ems_.dotnetRuntimeExports.releaseCSOwnedObject(jsHandle);
}
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 [View on GitHub (pinned to 290d5ab72c)
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.
Defensive patterns
Strategy: validation
Validate before calling
function assertInternalsShape(internals: unknown) {
if (!Array.isArray(internals)) {
throw new TypeError("Loader/runtime mismatch: internals must be an array");
}
} Type guard
const isInternalsArray = (v: unknown): v is unknown[] => Array.isArray(v);
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected internals to have RuntimeAPI
- Mismatched git hashes between loader and runtime. Loader: ${
- Mismatched git hashes between loader and runtime. Loader: ${
- Expected internals to be an array
- Expected internals to be an array
AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06).
Data as JSON: /api/errors/d24ab1bca1fe8147.
Report an issue: GitHub.