diff --git a/YKanBan/Services/AppServices.cs b/YKanBan/Services/AppServices.cs
index be70d9c..3e719e8 100644
--- a/YKanBan/Services/AppServices.cs
+++ b/YKanBan/Services/AppServices.cs
@@ -63,6 +63,16 @@ public sealed class AppServices : IDisposable
return Session;
}
+ ///
+ /// Releases the open workspace session, if any, so its lock and connection
+ /// do not outlive a workspace that could not be shown.
+ ///
+ public void CloseWorkspace()
+ {
+ Session?.Dispose();
+ Session = null;
+ }
+
///
/// Persists the configuration when this session changed a setting; called
/// once at shutdown. A write failure only loses this session's settings
diff --git a/YKanBan/ViewModels/MainWindowViewModel.cs b/YKanBan/ViewModels/MainWindowViewModel.cs
index ea712c7..c55db3b 100644
--- a/YKanBan/ViewModels/MainWindowViewModel.cs
+++ b/YKanBan/ViewModels/MainWindowViewModel.cs
@@ -114,7 +114,17 @@ public sealed partial class MainWindowViewModel : ViewModelBase
/// The opened workspace session.
private void ShowWorkspace(string folderPath, WorkspaceSession session)
{
- Content = new WorkspaceViewModel(session, ShowSettings, ShowAbout, _services.Config, _dialogs);
+ try
+ {
+ Content = new WorkspaceViewModel(session, ShowSettings, ShowAbout, _services.Config, _dialogs);
+ }
+ catch
+ {
+ // The first board read failed: the caller shows an error page, which holds no workspace.
+ _services.CloseWorkspace();
+ throw;
+ }
+
Title = $"{new DirectoryInfo(folderPath).Name} - {Resources.App_Name}";
}