{"record":{"id":"c1255e92a5e4bb4d","repo":"dotnet/runtime","slug":"expected-internals-to-be-an-array","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/diagnostics/index.ts","lineNumber":20,"sourceCode":"// The .NET Foundation licenses this file to you under the MIT license.\n\nimport type { DiagnosticsExportsTable, InternalExchange, DiagnosticsExports } from \"./types\";\nimport { InternalExchangeIndex } from \"../types\";\n\nimport GitHash from \"consts:gitHash\";\n\nimport { dotnetApi, dotnetUpdateInternals, dotnetUpdateInternalsSubscriber } from \"./cross-module\";\nimport { registerExit } from \"./exit\";\nimport { installNativeSymbols, symbolicateStackTrace } from \"./symbolicate\";\nimport { installLoggingProxy } from \"./console-proxy\";\nimport { collectMetrics } from \"./dotnet-counters\";\nimport { collectGcDump } from \"./dotnet-gcdump\";\nimport { collectCpuSamples } from \"./dotnet-cpu-profiler\";\nimport { connectDSRouter, ds_rt_websocket_close, ds_rt_websocket_create, ds_rt_websocket_poll, ds_rt_websocket_recv, ds_rt_websocket_send, initializeDS } from \"./diagnostic-server\";\nimport { ds_rt_browser_performance_measure } from \"./browser-profiler\";\n\nexport function dotnetInitializeModule(internals: InternalExchange): void {\n    if (!Array.isArray(internals)) throw new Error(\"Expected internals to be an array\");\n\n    const runtimeApi = internals[InternalExchangeIndex.RuntimeAPI];\n    if (typeof runtimeApi !== \"object\") throw new Error(\"Expected internals to have RuntimeAPI\");\n\n    if (runtimeApi.runtimeBuildInfo.gitHash && runtimeApi.runtimeBuildInfo.gitHash !== GitHash) {\n        throw new Error(`Mismatched git hashes between loader and runtime. Loader: ${runtimeApi.runtimeBuildInfo.gitHash}, Diagnostics: ${GitHash}`);\n    }\n\n    internals[InternalExchangeIndex.DiagnosticsExportsTable] = diagnosticsExportsToTable({\n        symbolicateStackTrace,\n        installNativeSymbols,\n        ds_rt_websocket_create,\n        ds_rt_websocket_send,\n        ds_rt_websocket_poll,\n        ds_rt_websocket_recv,\n        ds_rt_websocket_close,\n        ds_rt_browser_performance_measure,\n    });","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Native.Browser/diagnostics/index.ts#L2-L38","documentation":"Thrown by dotnetInitializeModule (diagnostics module) when the internals argument is not an array. The loader and runtime exchange state through a positional InternalExchange array; a non-array means the init contract was violated (wrong caller shape or version skew).","triggerScenarios":"Calling the diagnostics module's dotnetInitializeModule with an object, undefined, or a malformed value instead of the InternalExchange array produced by the loader.","commonSituations":"Custom bundler/loader that wraps or replaces internals; version mismatch between loader and diagnostics module; manually invoking the initializer with the wrong argument.","solutions":["Use the official loader entry points; do not call dotnetInitializeModule directly.","Ensure the diagnostics module and the loader/runtime are from the same build so the InternalExchange contract matches."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Guard the contract before initializing the diagnostics module\nif (!Array.isArray(internals)) {\n  throw new TypeError('dotnetInitializeModule expects the InternalExchange array from the loader.');\n}","typeGuard":"function isInternalExchange(x): x is InternalExchange {\n  return Array.isArray(x) && x.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Never call dotnetInitializeModule directly; let the loader drive module init.","Keep loader, runtime, and diagnostics module at the same build so the contract matches.","Add an Array.isArray assertion in dev builds to catch contract breakage early."],"tags":["initialization","internals","contract","version-mismatch"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}