{"record":{"id":"46a0f52112c644a8","repo":"LykosAI/StabilityMatrix","slug":"could-not-find-library-after-setting-path","errorCode":null,"errorMessage":"Could not find library after setting path","messagePattern":"Could not find library after setting path","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"StabilityMatrix/ViewModels/MainWindowViewModel.cs","lineNumber":147,"sourceCode":"        var updateWindow = new UpdateWindow(updateWindowViewModel)\n        {\n            Owner = Application.Current.MainWindow\n        };\n        updateWindow.ShowDialog();\n    }\n    \n    private async Task DoSettingsCheck()\n    {\n        // Check if library path is set\n        if (!settingsManager.TryFindLibrary())\n        {\n            await ShowPathSelectionDialog();            \n        }\n        \n        // Try to find library again, should be found now\n        if (!settingsManager.TryFindLibrary())\n        {\n            throw new Exception(\"Could not find library after setting path\");\n        }\n        \n        // Check if there are old packages, if so show migration dialog\n        if (settingsManager.GetOldInstalledPackages().Any())\n        {\n            var dialog = dialogFactory.CreateDataDirectoryMigrationDialog();\n            var result = await dialog.ShowAsync();\n            if (result == ContentDialogResult.None)\n            {\n                Application.Current.Shutdown();\n            }\n            else if (result == ContentDialogResult.Secondary)\n            {\n                var portableMarkerFile = Path.Combine(\"Data\", \".sm-portable\");\n                if (File.Exists(portableMarkerFile))\n                {\n                    File.Delete(portableMarkerFile);\n                }","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix/ViewModels/MainWindowViewModel.cs#L129-L165","documentation":"During startup, DoSettingsCheck attempts to locate the Stability Matrix library directory via settingsManager.TryFindLibrary. If no library is found, it shows a path selection dialog and retries; if the retry also fails, it throws this generic Exception because the app cannot function without a library.","triggerScenarios":"App startup (OnLoaded -> DoSettingsCheck) when no existing library is found and the user's path selection dialog flow still leaves TryFindLibrary returning false (cancelled dialog, selected folder not a valid library, unwritable path).","commonSituations":"First launch where the user cancels the folder picker; user picks an arbitrary folder that isn't a Stability Matrix library; portable-mode data folder missing or moved; permissions prevent reading the library marker file at the chosen location.","solutions":["Re-launch and complete the library path selection dialog, choosing the folder containing (or where you want) the Stability Matrix library.","Verify the selected directory contains the library marker (e.g. .stabilitymatrix) or let the app create a new library there.","Check read/write permissions on the chosen directory (especially under Program Files or network shares).","If a portable data folder was moved, restore it to the expected location next to the executable."],"exampleFix":"// before: dialog cancelled, exception thrown\nawait ShowPathSelectionDialog();\nif (!settingsManager.TryFindLibrary()) throw new Exception(\"Could not find library after setting path\");\n// after: keep prompting until a valid library is chosen\nwhile (!settingsManager.TryFindLibrary()) { if (!await ShowPathSelectionDialog()) return; }","handlingStrategy":"try-catch","validationCode":"if (!settingsManager.TryFindLibrary())\n{\n    var ok = await ShowPathSelectionDialog();\n    if (!ok || !settingsManager.TryFindLibrary()) return; // abort startup gracefully\n}","typeGuard":"static bool HasUsableLibrary(ISettingsManager s) =>\n    s.TryFindLibrary() && Directory.Exists(s.LibraryDir);","tryCatchPattern":"try { await vm.DoSettingsCheck(); }\ncatch (Exception ex) when (ex.Message == \"Could not find library after setting path\")\n{\n    logger.Warning(ex, \"No library configured; prompting user again\");\n    await ShowLibrarySetupFlow();\n}","preventionTips":["Complete the first-run library setup instead of cancelling the dialog.","Keep the library marker file intact and the folder accessible.","Avoid placing the library in permission-restricted locations.","Back up and restore settings/library paths together when migrating."],"tags":["startup","library","settings"],"backgroundTag":"directory-not-found","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}