I have a big problem using WP7 sandbox and applications. I used code from Adam Nathan 101 Windows Phone 7 apps volume 1 as the basis.
I have a settings page where the values ββcan be changed, and while the application is still working, they remain active and everything works fine. However, as soon as the application reaches my developer's phone, they are lost, and the application restarts with the default settings.
I do not know why these values ββare not stored. Any help would be greatly appreciated.
Here is the code I have, it is from the new adam nathan book. I tweeted him and he said that this should be done with a data type that is not serializable. I studied this, but I only use the double and bool values.
public class Setting<T>
{
string name;
T value;
T defaultValue;
bool hasValue;
public Setting(string name, T defaultValue)
{
this.name = name;
this.defaultValue = defaultValue;
}
public T Value
{
get
{
if (!this.hasValue)
{
if (IsolatedStorageSettings.ApplicationSettings.TryGetValue(this.name, out this.value))
{
this.value = this.defaultValue;
IsolatedStorageSettings.ApplicationSettings[this.name] = this.value;
}
this.hasValue = true;
}
return this.value;
}
set
{
IsolatedStorageSettings.ApplicationSettings[this.name] = value;
this.value = value;
this.hasValue = true;
}
}
public T DefaultValue
{
get { return this.defaultValue; }
}
public void ForceRefresh()
{
this.hasValue = false;
}
}
Further development:
I get this error when exiting the application:
The first exception of type "System.IO.IsolatedStorage.IsolatedStorageException" exception occurred in mscorlib.dll
ERROR FOUND: I am an idiot and left one exclamation point! from the trygetvalue part.
source
share