dotnet/runtime · critical · Error

Invalid runtime config, cannot initialize the runtime.

Error message

Invalid runtime config, cannot initialize the runtime.

What it means

Thrown by setupEmscripten when the loader config is missing required fields: resources, resources.assembly, resources.coreAssembly (non-empty), mainAssemblyName, virtualWorkingDirectory, and environmentVariables. These are normally generated by MSBuild into the runtime config; absence means the runtime cannot locate its assemblies or working directory.

Source

Thrown at src/native/libs/Common/JavaScript/host/index.ts:62

            map.loadIcuData,
            map.initializeCoreCLR,
            map.registerPdbBytes,
            map.instantiateWasm,
            map.instantiateWebcilModule,
        ];
    }
}

function setupEmscripten() {
    const loaderConfig = _ems_.dotnetApi.getConfig() as LoaderConfigInternal;
    if (!loaderConfig.resources ||
        !loaderConfig.resources.assembly ||
        !loaderConfig.resources.coreAssembly ||
        loaderConfig.resources.coreAssembly.length === 0 ||
        !loaderConfig.mainAssemblyName ||
        !loaderConfig.virtualWorkingDirectory ||
        !loaderConfig.environmentVariables) {
        throw new Error("Invalid runtime config, cannot initialize the runtime.");
    }

    for (const key in loaderConfig.environmentVariables) {
        _ems_.ENV[key] = loaderConfig.environmentVariables[key];
    }
}

export { BrowserHost_ExternalAssemblyProbe } from "./assets";

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Regenerate index.html and the runtime config via dotnet publish instead of hand-editing.
  2. Confirm the config JSON has resources.coreAssembly with at least one entry and a non-empty mainAssemblyName.
  3. Set virtualWorkingDirectory and environmentVariables in the loader options or generated config.
  4. Match the loader API version to the generated config schema of this SDK.

Example fix

// before: dotnet.create() with a stripped config object
dotnet.create({ resources: { assembly: [] } });
// after: pass the full generated config
dotnet.create(loadedRuntimeConfig); // has resources.coreAssembly, mainAssemblyName, etc.
Defensive patterns

Strategy: validation

Validate before calling

// Validate the generated config shape before creating the runtime
function isValidRuntimeConfig(c) {
  return !!(c?.resources?.assembly &&
           c.resources.coreAssembly?.length &&
           c.mainAssemblyName &&
           c.virtualWorkingDirectory &&
           c.environmentVariables);
}
if (!isValidRuntimeConfig(config)) {
  throw new Error('Runtime config is incomplete; regenerate via dotnet publish.');
}
await dotnet.create(config);

Type guard

function isLoaderConfigInternal(c): c is LoaderConfigInternal {
  return !!c
    && typeof c === 'object'
    && !!c.resources?.assembly
    && Array.isArray(c.resources?.coreAssembly) && c.resources.coreAssembly.length > 0
    && typeof c.mainAssemblyName === 'string'
    && typeof c.virtualWorkingDirectory === 'string'
    && typeof c.environmentVariables === 'object';
}

Prevention

When it happens

Trigger: dotnet.create() / runtime bootstrap where the MonoWasmRuntimeConfig (embedded in index.html or fetched JSON) is incomplete or hand-edited so any required field is undefined/empty.

Common situations: Manually editing index.html and stripping config; broken publish; pointing the loader at a config from a different project type; empty resources.coreAssembly because no assemblies were included.

Related errors


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