0
votes

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

1
How and with what values do you call this method?Euphoric
Look at the Can you provide the Exception.StackTrace property to find out where the exception is coming from. Track back what value was passed in to there and avoid passing that value.Peter Ritchie

1 Answers

1
votes

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.