dotnet/runtime · critical · Error

Expected internals to be an array

Error message

Expected internals to be an array

What it means

Thrown by libSystem.Native.Browser.extpost.js's dotnetInitializeModule when the internals argument is not an array. This is the same InternalExchange array contract as the TypeScript modules; a non-array means the native-module initializer was called with the wrong shape.

Source

Thrown at src/native/libs/System.Native.Browser/libSystem.Native.Browser.extpost.js:11

//
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-unused-vars */
var fetch = fetch || undefined; var dotnetNativeModuleLoaded = false; var dotnetInternals = null;
export function dotnetInitializeModule(internals) {
    if (dotnetNativeModuleLoaded) throw new Error("Native module already loaded");
    dotnetNativeModuleLoaded = true;
    if (!Array.isArray(internals)) throw new Error("Expected internals to be an array");
    dotnetInternals = internals;
    const runtimeApi = internals[0/*InternalExchangeIndex.RuntimeAPI*/];
    if (typeof runtimeApi !== "object") throw new Error("Expected internals to have RuntimeAPI");
    if (typeof runtimeApi.Module !== "object") throw new Error("Expected internals to have Module");
    return createDotnetRuntime(runtimeApi.Module);
}

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Use the official loader entry points; do not call dotnetInitializeModule directly.
  2. Ensure the native module JS and the loader/runtime are from the same build.
Defensive patterns

Strategy: type-guard

Validate before calling

// Guard the native-module init contract
if (!Array.isArray(internals)) {
  throw new TypeError('dotnetInitializeModule expects the InternalExchange array from the loader.');
}

Type guard

function isInternalExchangeArray(x): x is unknown[] {
  return Array.isArray(x);
}

Prevention

When it happens

Trigger: Calling the native module's dotnetInitializeModule with an object, undefined, or a malformed value instead of the InternalExchange array produced by the loader.

Common situations: Custom loader/wrapper that replaces internals; version mismatch between loader and native module JS; manually invoking the initializer incorrectly.

Related errors


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