From 93597bf13a7702abe164f0e30be854d3e6f6b17f Mon Sep 17 00:00:00 2001 From: Balaji Krishnan Date: Wed, 2 Mar 2016 15:04:15 -0800 Subject: [PATCH] Gaurd against trying to deserialize bad or .. .. corrupted data in SimpleCodeStyleOption --- .../Portable/CodeStyle/SimpleCodeStyleOption.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Features/Core/Portable/CodeStyle/SimpleCodeStyleOption.cs b/src/Features/Core/Portable/CodeStyle/SimpleCodeStyleOption.cs index fd3e24389b6..809d3500030 100644 --- a/src/Features/Core/Portable/CodeStyle/SimpleCodeStyleOption.cs +++ b/src/Features/Core/Portable/CodeStyle/SimpleCodeStyleOption.cs @@ -34,10 +34,19 @@ public SimpleCodeStyleOption(bool isChecked, NotificationOption notification) public static SimpleCodeStyleOption FromXElement(XElement element) { - var isChecked = bool.Parse(element.Attribute(nameof(IsChecked)).Value); - var severity = (DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity), element.Attribute(nameof(DiagnosticSeverity)).Value); - NotificationOption notificationOption; + var isCheckedAttribute = element.Attribute(nameof(IsChecked)); + var severityAttribute = element.Attribute(nameof(DiagnosticSeverity)); + + if (isCheckedAttribute == null || severityAttribute == null) + { + // data from storage is corrupt, or nothing has been stored yet. + return Default; + } + + var isChecked = bool.Parse(isCheckedAttribute.Value); + var severity = (DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity), severityAttribute.Value); + NotificationOption notificationOption; switch (severity) { case DiagnosticSeverity.Hidden: -- GitLab