From 25aa38afd3be3a5a210ddc380fe29b006433bd42 Mon Sep 17 00:00:00 2001 From: skibitsky Date: Mon, 16 Oct 2023 17:38:02 +0900 Subject: [PATCH] Revert "Merge branch 'fix/filesystem-hides-error' into release/2.1.1" This reverts commit a60ee6505f7c48dd339f867afe97ad3894124dcf, reversing changes made to d26757f437f4b17b1b8baa2da0867eb7977ffd1f. --- .../FileSystemStorage.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Core Modules/WalletConnectSharp.Storage/FileSystemStorage.cs b/Core Modules/WalletConnectSharp.Storage/FileSystemStorage.cs index 60dbe45..2376614 100644 --- a/Core Modules/WalletConnectSharp.Storage/FileSystemStorage.cs +++ b/Core Modules/WalletConnectSharp.Storage/FileSystemStorage.cs @@ -110,8 +110,23 @@ private async Task Load() await _semaphoreSlim.WaitAsync(); var json = await File.ReadAllTextAsync(FilePath, Encoding.UTF8); _semaphoreSlim.Release(); - Entries = JsonConvert.DeserializeObject>(json, - new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); + + try + { + Entries = JsonConvert.DeserializeObject>(json, + new JsonSerializerSettings() {TypeNameHandling = TypeNameHandling.Auto}); + } + catch (JsonSerializationException e) + { + // Move the file to a .unsupported file + // and start fresh + WCLogger.LogError(e); + WCLogger.LogError("Cannot load JSON file, moving data to .unsupported file to force continue"); + if (File.Exists(FilePath + ".unsupported")) + File.Move(FilePath + ".unsupported", FilePath + "." + Guid.NewGuid() + ".unsupported"); + File.Move(FilePath, FilePath + ".unsupported"); + Entries = new Dictionary(); + } } } }