diff --git a/Source/AppScaffolding/AppScaffolding.csproj b/Source/AppScaffolding/AppScaffolding.csproj index 07bc3594..61400c70 100644 --- a/Source/AppScaffolding/AppScaffolding.csproj +++ b/Source/AppScaffolding/AppScaffolding.csproj @@ -2,7 +2,7 @@ net6.0 - 8.5.0.1 + 8.5.1.1 diff --git a/Source/LibationFileManager/FilePathCache.cs b/Source/LibationFileManager/FilePathCache.cs index 1f096990..56eddddb 100644 --- a/Source/LibationFileManager/FilePathCache.cs +++ b/Source/LibationFileManager/FilePathCache.cs @@ -24,23 +24,24 @@ namespace LibationFileManager static FilePathCache() { // load json into memory. if file doesn't exist, nothing to do. save() will create if needed - if (File.Exists(jsonFile)) - { - var list = JsonConvert.DeserializeObject>(File.ReadAllText(jsonFile)); + if (!File.Exists(jsonFile)) + return; - // file exists but deser is null. this will never happen when file is healthy - if (list is null) - { - lock (locker) - { - Serilog.Log.Logger.Error("Error deserializing file. Wrong format. Possibly corrupt. Deleting file. {@DebugInfo}", new { jsonFile }); - File.Delete(jsonFile); - return; - } - } + try + { + var list = JsonConvert.DeserializeObject>(File.ReadAllText(jsonFile)); + if (list is null) + throw new NullReferenceException("File exists but deserialize is null. This will never happen when file is healthy."); - cache = new Cache(list); - } + cache = new Cache(list); + } + catch (Exception ex) + { + Serilog.Log.Logger.Error(ex, "Error deserializing file. Wrong format. Possibly corrupt. Deleting file. {@DebugInfo}", new { jsonFile }); + lock (locker) + File.Delete(jsonFile); + return; + } } public static bool Exists(string id, FileType type) => GetFirstPath(id, type) is not null;