dotnet/aspnetcore · error · Error

Blazor has already started.

Error message

Blazor has already started.

What it means

Thrown by boot() in Boot.Server.ts when the module-level 'started' flag is already true. This is the top-level guard for the Blazor Server boot entrypoint and means the application has already initialized; a second boot would double-register root components, re-attach the dispatcher, and re-run initializers.

Solutions

  1. Call Blazor.start() exactly once; remove duplicate invocations.
  2. Disable autostart (autostart="false") and start manually from a single place.
  3. Memoize the boot promise at your call site so retries/re-entries return the same promise.
  4. Audit module duplication if HMR or bundler config could re-evaluate Boot.Server.

Example fix

// before
window.addEventListener('load', () => Blazor.start());
// plus autostart=true in the script tag -> second boot throws

// after
<script src="blazor.web.js" autostart="false"></script>
<script>
  window.addEventListener('load', () => Blazor.start());
</script>
Defensive patterns

Strategy: validation

Validate before calling

// Single guarded entrypoint for Server boot.
let started;
function bootServerOnce(opts) {
  if (started) return started;
  started = Blazor.start(opts);
  return started;
}

Try / catch

try {
  await Blazor.start(opts);
} catch (e) {
  if (/already started/.test(e.message)) return;
  throw e;
}

Prevention

When it happens

Trigger: Calling the Server boot entrypoint (Blazor.start in a Server-configured app, or the boot function directly) more than once per page load.

Common situations: Autostart left enabled while a script also calls Blazor.start(); a micro-frontend or shell that re-runs boot on route change; bundler duplication evaluating Boot.Server.ts twice; a retry-on-error handler that re-invokes boot after partial success.

Related errors


AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11). Data as JSON: /api/errors/e2525e2b0c61cb9a. Report an issue: GitHub.

Appendix: source

Thrown at src/Components/Web.JS/src/Boot.Server.ts:19

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

import { Blazor } from './GlobalExports';
import { shouldAutoStart } from './BootCommon';
import { CircuitStartOptions, resolveOptions } from './Platform/Circuits/CircuitStartOptions';
import { setCircuitOptions, startServer } from './Boot.Server.Common';
import { ServerComponentDescriptor, discoverComponents } from './Services/ComponentDescriptorDiscovery';
import { DotNet } from '@microsoft/dotnet-js-interop';
import { InitialRootComponentsList } from './Services/InitialRootComponentsList';
import { JSEventRegistry } from './Services/JSEventRegistry';

type BlazorServerStartOptions = Partial<CircuitStartOptions> & { circuit?: Partial<CircuitStartOptions> };

let started = false;

function boot(userOptions?: BlazorServerStartOptions): Promise<void> {
  if (started) {
    throw new Error('Blazor has already started.');
  }
  started = true;

  // Accept the `circuit` property from the blazor.web.js options format
  const normalizedOptions = userOptions?.circuit ?? userOptions;
  const configuredOptions = resolveOptions(normalizedOptions);
  setCircuitOptions(Promise.resolve(configuredOptions || {}));

  const serverComponents = discoverComponents(document, 'server') as ServerComponentDescriptor[];
  const components = new InitialRootComponentsList(serverComponents);
  return startServer(components, JSEventRegistry.create(Blazor));
}

Blazor.start = boot;
window['DotNet'] = DotNet;

if (shouldAutoStart()) {
  boot();

View on GitHub (pinned to 3600ca084e)