title: System.Collections.Generic.KeyNotFoundException For Seemingly No Reason
body: <p>Here is my code for some settings</p>
  
  <pre><code>if (settings.Contains("dynamicOn"))
          {
              // Commenting out because we're trying a different way
              // DynamicCheck.IsChecked = (bool)settings["dynamicOn"];
              dynamicToggle.IsChecked = (bool)settings["dynamicOn"];
              AllPacks.IsChecked = (bool)settings["changeAllPacks"];
          }
  </code></pre>
  
  <p>And here is the XAML behind it</p>
  
  <pre><code> &lt;toolkit:ToggleSwitch x:Name="dynamicToggle" Header="Dynamically Update Lockscreen?" Margin="0,112,0,-112" SwitchForeground="White" Checked="DynamicCheck_Checked_1" Unchecked="DynamicCheck_Unchecked"&gt;
                          &lt;toolkit:ToggleSwitch.HeaderTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;ContentControl Content="{Binding}"/&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/toolkit:ToggleSwitch.HeaderTemplate&gt;
                      &lt;/toolkit:ToggleSwitch&gt;
                      &lt;CheckBox x:Name="AllPacks" Content="All Packs" Checked="AllPacks_Checked" Unchecked="AllPacks_Unchecked" Margin="50,174,0,0" Visibility="Collapsed"/&gt;
  </code></pre>
  
  <p>Now, the XAML works fine, as well as the ToggleSwitch. All that works. Just, when I try to actually open up my settings page (which opens just fine without the CheckBox stuff, but refuses to open with it), I get this error</p>
  
  <pre><code>A first chance exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.ni.dll The program '[3048] TaskHost.exe' has exited with code -1 (0xffffffff).
  </code></pre>
  
  <p>Has anyone seen this before? Searching Bing doesn't seem to have anything for me.
  Any help would be greatly appreciated!</p>
  
  <p>Thanks,
  Patrick</p>
  
  <p>EDIT:
  I've changed the code to this </p>
  
  <pre><code>if (settings.Contains("dynamicOn"))
          {
              // Commenting out because we're trying a different way
              // DynamicCheck.IsChecked = (bool)settings["dynamicOn"];
              AllPacks.IsChecked = (bool)settings["changeAllPacks"];
              dynamicToggle.IsChecked = (bool)settings["dynamicOn"];
          }
          else
          {
              // Commenting out because we're trying a different way
              // DynamicCheck.IsChecked = true;
              // isEnabledText.Visibility = Visibility.Visible;
              // settings.Add("dynamicOn", true);
              dynamicToggle.IsChecked = true;
              AllPacks.IsChecked = true;
              AllPacks.Visibility = Visibility.Visible;
              settings.Add("changeAllPacks", true);
              settings.Add("dynamicOn", true);
          }
  </code></pre>
  
  <p>And now it errors on the </p>
  
  <pre><code>settings.Add("dynamicOn", true);
  </code></pre>
  
  <p>And the error has also changed to </p>
  
  <pre><code>A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
  </code></pre>
  
  <p>So, I'm starting to think that this might be an IsolatedStorage issue?</p>