dotnet/runtime · error · Error

Failed to invoke 'onRuntimeConfigLoaded' on library…

Error message

Failed to invoke 'onRuntimeConfigLoaded' on library initializer '${name}': ${message}

What it means

Thrown by callLibraryInitializerOnRuntimeConfigLoaded() (src/native/libs/Common/JavaScript/loader/assets.ts:72). It loads a library-initializer JS module and invokes its onRuntimeConfigLoaded(config) hook; if the hook throws (or rejects), the loader wraps the cause and re-throws so the failure is attributable to the offending initializer by name.

Solutions

  1. Inspect the wrapped error.cause and the named initializer to find the real exception, then fix the initializer.
  2. Make onRuntimeConfigLoaded defensive about optional config fields (feature-detect before reading).
  3. Ensure the initializer is built/tested against the runtime version whose config shape it expects.

Example fix

// before: initializer throws on missing field
export function onRuntimeConfigLoaded(config) {
  doSetup(config.globalization.icuData); // TypeError if undefined
}

// after
export function onRuntimeConfigLoaded(config) {
  const icu = config?.globalization?.icuData;
  if (icu) doSetup(icu);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// best-effort: confirm the initializer exports the hook before relying on it
async function safeHook(mod: any, cfg: any): Promise<void> {
  if (typeof mod?.onRuntimeConfigLoaded === 'function') {
    await mod.onRuntimeConfigLoaded(cfg);
  }
}

Type guard

function hasOnRuntimeConfigLoaded(m: any): m is { onRuntimeConfigLoaded: (c: any) => void | Promise<void> } {
  return typeof m?.onRuntimeConfigLoaded === 'function';
}

Try / catch

try {
  await callLibraryInitializerOnRuntimeConfigLoaded(asset);
} catch (err) {
  // err.cause is the initializer's real error; fix that initializer
  console.error('Initializer failed:', (err as Error).message, (err as any).cause);
  throw err;
}

Prevention

When it happens

Trigger: A module listed in resources.modulesAfterConfigLoaded exports onRuntimeConfigLoaded; the loader calls it with loaderConfig; if it throws synchronously or returns a rejected promise, the catch at line 80 wraps and rethrows.

Common situations: A custom library initializer that reads a missing config field and throws; an initializer written against an older/newer config shape; an initializer that makes a network call which fails; a bug in the initializer's onRuntimeConfigLoaded body.

Related errors


AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10). Data as JSON: /api/errors/74ddbcd7c22face8. Report an issue: GitHub.

Appendix: source

Thrown at src/native/libs/Common/JavaScript/loader/assets.ts:82

        if (!asset.resolvedUrl) throw new Error("Invalid config, resources is not set");
        mod = await import(/* webpackIgnore: true */ asset.resolvedUrl);
        asset.moduleExports = mod;
    }
    onDownloadedAsset(assetInternal);
    return mod;
}

export async function callLibraryInitializerOnRuntimeConfigLoaded(asset: JsAsset): Promise<any> {
    const module = await loadJSModule(asset);
    const name = asset.name || asset.resolvedUrl || "unknown";
    try {
        if (typeof module.onRuntimeConfigLoaded === "function") {
            await module.onRuntimeConfigLoaded(loaderConfig);
        }
        return module;
    } catch (err) {
        const message = err instanceof Error ? err.message : String(err);
        throw new Error(`Failed to invoke 'onRuntimeConfigLoaded' on library initializer '${name}': ${message}`, { cause: err });
    }
}

export async function callLibraryInitializerOnRuntimeReady([asset, modulePromise]: [JsAsset, Promise<any>]): Promise<void> {
    const module = await modulePromise;
    const name = asset.name || asset.resolvedUrl || "unknown";
    try {
        if (typeof module.onRuntimeReady === "function") {
            await module.onRuntimeReady(dotnetApi);
        }
    } catch (err) {
        const message = err instanceof Error ? err.message : String(err);
        throw new Error(`Failed to invoke 'onRuntimeReady' on library initializer '${name}': ${message}`, { cause: err });
    }
}

export function fetchMainWasm(asset: WasmAsset): Promise<Response> {
    totalAssetsToDownload++;

View on GitHub (pinned to 60108ba66e)