{"record":{"id":"5d22ee4a51af8735","repo":"microsoft/aspire","slug":"the-dashboard-database-schema-was-initialized-to-version","errorCode":null,"errorMessage":"The dashboard database schema was initialized to version {FormatSchemaVersion(initializedSchemaVersion)} instead of the expected version {SchemaVersion}.","messagePattern":"The dashboard database schema was initialized to version (.+?) instead of the expected version (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Dashboard/ServiceClient/DashboardSqliteDatabase.cs","lineNumber":169,"sourceCode":"            if (schemaTableExists)\n            {\n                var existingSchemaVersion = GetSchemaVersion(connection, transaction: null);\n                if (existingSchemaVersion != SchemaVersion)\n                {\n                    throw new InvalidOperationException($\"The dashboard database schema version {FormatSchemaVersion(existingSchemaVersion)} does not match the expected version {SchemaVersion}.\");\n                }\n            }\n\n            using var transaction = connection.BeginTransaction();\n            foreach (var script in s_schemaScripts.Value)\n            {\n                connection.Execute(script, new { SchemaVersion }, transaction);\n            }\n\n            var initializedSchemaVersion = GetSchemaVersion(connection, transaction);\n            if (initializedSchemaVersion != SchemaVersion)\n            {\n                throw new InvalidOperationException($\"The dashboard database schema was initialized to version {FormatSchemaVersion(initializedSchemaVersion)} instead of the expected version {SchemaVersion}.\");\n            }\n            transaction.Commit();\n            _schemaInitialized = true;\n        }\n    }\n\n    /// <summary>\n    /// Throws an exception with the specified message when the database is read-only.\n    /// </summary>\n    /// <param name=\"message\">The exception message used when the database is read-only.</param>\n    /// <exception cref=\"InvalidOperationException\">The database is read-only.</exception>\n    public void EnsureWritable(string message)\n    {\n        if (IsReadOnly)\n        {\n            throw new InvalidOperationException(message);\n        }\n    }","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Dashboard/ServiceClient/DashboardSqliteDatabase.cs#L151-L187","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Delete the database file and reinitialize with an unmodified build of the dashboard binaries","Reinstall/restore the original Aspire.Dashboard package — embedded scripts may be corrupted or modified","Ensure no other process is concurrently writing the database during initialization"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await database.InitializeSchemaAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"was initialized to version\"))\n{\n    // treat as corrupted install: delete db and reinstall the package\n    File.Delete(dbPath);\n}","preventionTips":["Use official, unmodified Aspire.Dashboard builds","Avoid concurrent writers while schema initialization runs","Delete and recreate databases that report initialization mismatches"],"tags":["dashboard","sqlite","schema","invariant","internal-error"],"backgroundTag":"internal-invariant-violation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}