microsoft/aspire · error

The dashboard database schema was initialized to version

Error message

The dashboard database schema was initialized to version {FormatSchemaVersion(initializedSchemaVersion)} instead of the expected version {SchemaVersion}.

What it means

After executing the embedded schema scripts inside a transaction, InitializeSchemaAsync re-reads the schema version and asserts it equals the expected SchemaVersion. It throws InvalidOperationException if the scripts produced a different version — an internal invariant check that the schema initialization didn't behave as intended (e.g. scripts didn't record the version correctly).

Solutions

  1. Delete the database file and reinitialize with an unmodified build of the dashboard binaries
  2. Reinstall/restore the original Aspire.Dashboard package — embedded scripts may be corrupted or modified
  3. Ensure no other process is concurrently writing the database during initialization
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    await database.InitializeSchemaAsync();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("was initialized to version"))
{
    // treat as corrupted install: delete db and reinstall the package
    File.Delete(dbPath);
}

Prevention

When it happens

Trigger: Schema scripts executed but GetSchemaVersion (within the transaction) returns a value other than SchemaVersion — corrupted/partially-applied embedded scripts, a script writing an unexpected version, or interference from a concurrent writer.

Common situations: Tampered or mismatched embedded .sql resources (modified assemblies/custom builds); a database file corrupted mid-transaction; running a patched build where schema scripts and SchemaVersion constant drifted apart.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/5d22ee4a51af8735. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Dashboard/ServiceClient/DashboardSqliteDatabase.cs:169

            if (schemaTableExists)
            {
                var existingSchemaVersion = GetSchemaVersion(connection, transaction: null);
                if (existingSchemaVersion != SchemaVersion)
                {
                    throw new InvalidOperationException($"The dashboard database schema version {FormatSchemaVersion(existingSchemaVersion)} does not match the expected version {SchemaVersion}.");
                }
            }

            using var transaction = connection.BeginTransaction();
            foreach (var script in s_schemaScripts.Value)
            {
                connection.Execute(script, new { SchemaVersion }, transaction);
            }

            var initializedSchemaVersion = GetSchemaVersion(connection, transaction);
            if (initializedSchemaVersion != SchemaVersion)
            {
                throw new InvalidOperationException($"The dashboard database schema was initialized to version {FormatSchemaVersion(initializedSchemaVersion)} instead of the expected version {SchemaVersion}.");
            }
            transaction.Commit();
            _schemaInitialized = true;
        }
    }

    /// <summary>
    /// Throws an exception with the specified message when the database is read-only.
    /// </summary>
    /// <param name="message">The exception message used when the database is read-only.</param>
    /// <exception cref="InvalidOperationException">The database is read-only.</exception>
    public void EnsureWritable(string message)
    {
        if (IsReadOnly)
        {
            throw new InvalidOperationException(message);
        }
    }

View on GitHub (pinned to 25830f84bd)