dotnet/aspnetcore · error · InvalidOperationException
' ' already initialized.
Error message
'{GetType().Name}' already initialized. What it means
NavigationManager.Initialize can only be called once. It sets BaseUri and Uri before first use; a second call throws InvalidOperationException because re-initializing would invalidate already-issued URIs and subscribers.
Solutions
- Guard the Initialize call so it runs only once per instance.
- Create a fresh NavigationManager instance when re-initialization is genuinely needed.
- Restructure the lifecycle so initialization happens at startup only.
Example fix
// before
manager.Initialize(baseUri, uri); // called again
// after
if (!manager.IsInitialized)
{
manager.Initialize(baseUri, uri);
} Defensive patterns
Strategy: validation
Validate before calling
// Guard Initialize so it runs once per instance.
if (!_isInitialized)
{
Initialize(baseUri, uri);
} Prevention
- Call NavigationManager.Initialize exactly once per instance lifecycle.
- Create a new instance for tests instead of re-initializing a shared one.
- Guard reconnection/middleware paths to skip Initialize if already initialized.
When it happens
Trigger: Calling Initialize twice, e.g. during Blazor Server reconnection, middleware that re-initializes, or test setup that reuses an instance.
Common situations: Blazor Server reconnection paths that re-init, custom hosting that calls Initialize on every request, or unit tests sharing a NavigationManager instance across cases.
Related errors
- No enhanced programmatic navigation handler has been…
- The type does not support supplying . To add support, that…
- The URI ' ' is not a relative URI. When…
- Descriptors must be assigned a renderer ID before getting…
- ' ' has not been initialized.
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/5b186f3194812e81.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Components/src/NavigationManager.cs:288
else
{
_notFound.Invoke(this, new NotFoundEventArgs());
}
}
/// <summary>
/// Called to initialize BaseURI and current URI before these values are used for the first time.
/// Override <see cref="EnsureInitialized" /> and call this method to dynamically calculate these values.
/// </summary>
protected void Initialize(string baseUri, string uri)
{
// Make sure it's possible/safe to call this method from constructors of derived classes.
ArgumentNullException.ThrowIfNull(uri);
ArgumentNullException.ThrowIfNull(baseUri);
if (_isInitialized)
{
throw new InvalidOperationException($"'{GetType().Name}' already initialized.");
}
_isInitialized = true;
// Setting BaseUri before Uri so they get validated.
BaseUri = baseUri;
Uri = uri;
}
/// <summary>
/// Allows derived classes to lazily self-initialize. Implementations that support lazy-initialization should override
/// this method and call <see cref="Initialize(string, string)" />.
/// </summary>
protected virtual void EnsureInitialized()
{
}
/// <summary>View on GitHub (pinned to 3600ca084e)