Search code examples
c#visual-studio-2012exceptionisolatedstorage

System.InvalidCastException with string isolatedstorage


I get this exception on the following code. An exception of type 'System.InvalidCastException' occurred in Project.DLL but was not handled in user code.

if (IsolatedStorageSettings.ApplicationSettings.Contains("0"))
{
    string temp = (string)IsolatedStorageSettings.ApplicationSettings["0"];//exception here
}

What am I doing wrong?


Solution

  • I had the same problem! Here is what I did:

    if (IsolatedStorageSettings.ApplicationSettings.Contains("0"))
    {
       string temp = IsolatedStorageSettings.ApplicationSettings["0"].ToString();
    }