diff --git a/MainWindow.cs b/MainWindow.cs index 7f0d5b8..7ff5e65 100644 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -49,7 +49,7 @@ namespace AntdUIDemo { // 读取 appsettings.json 文件 var appSettings = ConfigurationHelper.GetAppSettings(); - + if (appSettings == null) return; // 加载色彩模式 var value = appSettings["ColorMode"]?.ToString(); if (value == "Auto") @@ -86,6 +86,7 @@ namespace AntdUIDemo { // 读取 appsettings.json 文件 var appSettings = ConfigurationHelper.GetAppSettings(); + if (appSettings == null) return; var value = appSettings["ColorMode"]?.ToString(); if (value == "Auto") { diff --git a/Utils/ConfigurationHelper.cs b/Utils/ConfigurationHelper.cs index 3a251cd..bd4e982 100644 --- a/Utils/ConfigurationHelper.cs +++ b/Utils/ConfigurationHelper.cs @@ -12,6 +12,10 @@ namespace AntdUIDemo.Utils { public static JObject GetAppSettings(string configFilePath = "appsettings.json") { + if (!File.Exists(configFilePath)) + { + return null; + } // Read the JSON file var json = File.ReadAllText(configFilePath);