I'm making a project for windows phone 8 using C# and I want to be able to save some strings to storage so the next time the user opens the app, He'll be able to have the strings he saved last time he opened it.
I set it like this:
IsolatedStorageSettings.ApplicationSettings["key"] = SetKey.Text;
and I try to get it like this:
if (IsolatedStorageSettings.ApplicationSettings.Contains("key"))
{
string GetKey = (string)IsolatedStorageSettings.ApplicationSettings["key"];
}
SetKey is the name of a TextBox.
The problem is that when I run this I get an unhandled exception at the code line that is in the if, saying:
An exception of type 'System.InvalidCastException' occurred in ProjectName.DLL but was not handled in user code.
if (IsolatedStorageSettings.ApplicationSettings.Contains("key") &&
IsolatedStorageSettings.ApplicationSettings["key"] != null)
{
string GetKey = IsolatedStorageSettings.ApplicationSettings["key"].ToString();
}
Try like this ! Probably key
is null.