From 6d72c6647e2d07c95cb1cc664595068562db9741 Mon Sep 17 00:00:00 2001 From: Matthew Lopez <73856503+MatthewL246@users.noreply.github.com> Date: Tue, 30 Aug 2022 17:49:12 -0400 Subject: [PATCH] Fix crash when saving account data Apparently, SelectedItem cannot be casted to a nullable type. This also expands the try block to prevent any other possible crashes when saving account data. --- MainWindow.xaml.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 3a1b9b0..eed5f35 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -501,24 +501,24 @@ private void ReloadOrStop(object sender, RoutedEventArgs e) /// Saves the current account's login info and settings. private async Task SaveAccountDataAsync() { - JsonObject accountDataObject = new() + try { - ["username"] = username.Text, - ["password"] = passwordHash.Password, + JsonObject accountDataObject = new() + { + ["username"] = username.Text, + ["password"] = passwordHash.Password, - ["accountServer"] = accountServer.Text, - ["discoveryServer"] = discoveryServer.Text, - ["portalServer"] = portalServer.Text, + ["accountServer"] = accountServer.Text, + ["discoveryServer"] = discoveryServer.Text, + ["portalServer"] = portalServer.Text, - ["languageId"] = (int?)languageBox.SelectedItem, - ["countryId"] = (int?)countryBox.SelectedItem, - ["console"] = (string?)consoleSelect.SelectedItem, - }; + ["languageId"] = (int)languageBox.SelectedItem, + ["countryId"] = (int)countryBox.SelectedItem, + ["console"] = (string)consoleSelect.SelectedItem, + }; - JsonSerializerOptions options = new() { WriteIndented = true }; + JsonSerializerOptions options = new() { WriteIndented = true }; - try - { await File.WriteAllTextAsync(accountDataJsonPath, accountDataObject.ToJsonString(options)); } catch (Exception ex)