{"record":{"id":"3dad603a0e761efc","repo":"microsoft/aspire","slug":"unexpected-dashboard-persistence-mode-persistencemode","errorCode":null,"errorMessage":"Unexpected dashboard persistence mode: {PersistenceMode}","messagePattern":"Unexpected dashboard persistence mode: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Dashboard/ServiceClient/DashboardRunStore.cs","lineNumber":192,"sourceCode":"                            DatabasePath,\n                            SchemaVersion);\n                        DeleteDatabaseFiles(DatabasePath);\n                    }\n                    else\n                    {\n                        _logger.LogDebug(\"Resuming dashboard database at '{DatabasePath}'.\", DatabasePath);\n                    }\n\n                    _runLock = resumeRunLock;\n                }\n                catch\n                {\n                    resumeRunLock.Dispose();\n                    throw;\n                }\n                break;\n            default:\n                throw new InvalidOperationException($\"Unexpected dashboard persistence mode: {PersistenceMode}\");\n        }\n\n        _metadata = new DashboardRunMetadata\n        {\n            SchemaVersion = SchemaVersion,\n            RunId = runId,\n            StartedAtUtc = startedAt,\n            ApplicationName = options.Value.ApplicationName,\n            DatabaseFileName = Path.GetFileName(DatabasePath)\n        };\n        _runs = new(LoadRuns);\n\n        _logger.LogDebug(\n            \"Dashboard run store initialized with persistence mode '{PersistenceMode}'. Current working directory: '{CurrentWorkingDirectory}'. Database path: '{DatabasePath}'.\",\n            PersistenceMode,\n            CurrentWorkingDirectory,\n            DatabasePath);\n    }","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Dashboard/ServiceClient/DashboardRunStore.cs#L174-L210","documentation":"DashboardRunStore's constructor switches on the configured PersistenceMode to decide how to initialize persistence (e.g. create, resume, none). The default branch throws InvalidOperationException because the mode value is outside the set of supported persistence modes.","triggerScenarios":"Constructing DashboardRunStore with a PersistenceMode value that is not one of the recognized enum members (an undefined enum value, or an out-of-range cast).","commonSituations":"A dashboard option/env configuration produced an invalid or undefined PersistenceMode; casting an int to the enum type without validation; a new mode added in a newer library version being passed to an older build.","solutions":["Set PersistenceMode to a supported value defined by the dashboard's persistence options","Validate the persisted/configured mode value with Enum.IsDefined before constructing the store","If the value comes from config parsing, fix the config source or upgrade the package so the mode is recognized"],"exampleFix":"// before\nvar store = new DashboardRunStore((PersistenceMode)someInt);\n\n// after\nvar mode = Enum.IsDefined(typeof(PersistenceMode), someInt) ? (PersistenceMode)someInt : PersistenceMode.None;\nvar store = new DashboardRunStore(mode);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(PersistenceMode), configuredMode))\n{\n    configuredMode = PersistenceMode.None; // or fail fast with a clear config error\n}","typeGuard":"bool IsValidPersistenceMode(PersistenceMode mode) => Enum.IsDefined(typeof(PersistenceMode), mode);","tryCatchPattern":"try\n{\n    var store = new DashboardRunStore(mode);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unexpected dashboard persistence mode\"))\n{\n    // log the raw config value and fall back to a supported mode\n}","preventionTips":["Only assign enum members defined by PersistenceMode","Validate int-to-enum casts with Enum.IsDefined","Validate config/env values before constructing the store"],"tags":["dashboard","persistence","enum","invalid-value"],"backgroundTag":"invalid-enum-value","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"}