问题描述:

I am in the throes of finishing up my 1st WP7 app, and I am now experiencing a strange error that has just popped up.

When I save data back to the Local Storage (Add mode) I get an error saying "Value does not fall within the expected range" This only accurs with a new key item, the update works fine.

Anyone got any thoughts or ideas?

 // -----------------------------------------------------------------------------

//Setting the fileName

// IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;

// -----------------------------------------------------------------------------

// -------------------------------Local Storage----------------------------------------------

public void setLocalStorage(string key, object value) {

try

{

// add new Anchorage/drift values

appSettings.Add(key, value);

}

catch (ArgumentException ex)

{

MessageBox.Show("An error occurred during writing the key " + key + ex, "ERROR", MessageBoxButton.OK);

}

}

// ---------------------------------------------------------------------------------

Thanks in advance

Phill

网友答案:

You'd get this if you were trying to add an item with a key which already exists.

Make sure you're not trying to add when the key which already exists.

The general pattern for working with the settings dictionary is to create a single method to add or update and that internally checks for the existence of the key and then either adds or updates the entry as appropriate.

相关阅读:
Top