From c244596c007ddc5fdf2109766c2ff487d61b5b92 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Wed, 23 Nov 2016 13:48:28 -0800 Subject: [PATCH] Deal with booleans that had been converted to integers in the cloud Previously, we would return the incorrectly typed data and then we'd crash downstream of that. Now we'll be more robust, dealing with this legacy data. Other type mismatches will also be thrown out now. Fixes dotnet/roslyn#15214. --- ...amingVisualStudioProfileOptionPersister.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/Options/RoamingVisualStudioProfileOptionPersister.cs b/src/VisualStudio/Core/Def/Implementation/Options/RoamingVisualStudioProfileOptionPersister.cs index 0231050f0d047..1f57642c3b919 100644 --- a/src/VisualStudio/Core/Def/Implementation/Options/RoamingVisualStudioProfileOptionPersister.cs +++ b/src/VisualStudio/Core/Def/Implementation/Options/RoamingVisualStudioProfileOptionPersister.cs @@ -132,9 +132,28 @@ public bool TryFetch(OptionKey optionKey, out object value) } else { - value = optionKey.Option.DefaultValue; + value = null; + return false; } } + else if (optionKey.Option.Type == typeof(bool) && value is int intValue) + { + // TypeScript used to store some booleans as integers. We now handle them properly for legacy sync scenarios. + value = intValue != 0; + return true; + } + else if (optionKey.Option.Type == typeof(bool) && value is long longValue) + { + // TypeScript used to store some booleans as integers. We now handle them properly for legacy sync scenarios. + value = longValue != 0; + return true; + } + else if (value != null && optionKey.Option.Type != value.GetType()) + { + // We got something back different than we expected, so fail to deserialize + value = null; + return false; + } return true; } @@ -189,4 +208,4 @@ public bool TryPersist(OptionKey optionKey, object value) return true; } } -} \ No newline at end of file +}