{"record":{"id":"6272035f05f90da2","repo":"dotnet/runtime","slug":"expected-internals-to-be-an-array-627203","errorCode":null,"errorMessage":"Expected internals to be an array","messagePattern":"Expected internals to be an array","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/native/libs/System.Native.Browser/libSystem.Native.Browser.extpost.js","lineNumber":11,"sourceCode":"//\n// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\n/* eslint-disable no-undef */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nvar fetch = fetch || undefined; var dotnetNativeModuleLoaded = false; var dotnetInternals = null;\nexport function dotnetInitializeModule(internals) {\n    if (dotnetNativeModuleLoaded) throw new Error(\"Native module already loaded\");\n    dotnetNativeModuleLoaded = true;\n    if (!Array.isArray(internals)) throw new Error(\"Expected internals to be an array\");\n    dotnetInternals = internals;\n    const runtimeApi = internals[0/*InternalExchangeIndex.RuntimeAPI*/];\n    if (typeof runtimeApi !== \"object\") throw new Error(\"Expected internals to have RuntimeAPI\");\n    if (typeof runtimeApi.Module !== \"object\") throw new Error(\"Expected internals to have Module\");\n    return createDotnetRuntime(runtimeApi.Module);\n}\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Native.Browser/libSystem.Native.Browser.extpost.js#L1-L18","documentation":"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.","triggerScenarios":"Calling the native module's dotnetInitializeModule with an object, undefined, or a malformed value instead of the InternalExchange array produced by the loader.","commonSituations":"Custom loader/wrapper that replaces internals; version mismatch between loader and native module JS; manually invoking the initializer incorrectly.","solutions":["Use the official loader entry points; do not call dotnetInitializeModule directly.","Ensure the native module JS and the loader/runtime are from the same build."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Guard the native-module init contract\nif (!Array.isArray(internals)) {\n  throw new TypeError('dotnetInitializeModule expects the InternalExchange array from the loader.');\n}","typeGuard":"function isInternalExchangeArray(x): x is unknown[] {\n  return Array.isArray(x);\n}","tryCatchPattern":null,"preventionTips":["Never call the native module's dotnetInitializeModule directly; use the loader.","Keep the native module JS and loader at the same build.","Assert Array.isArray in dev to catch contract breakage."],"tags":["initialization","internals","contract","version-mismatch"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}