Dan
Dan

Reputation: 2344

Unhandled Exception when trying to save data in Win Mobile 8 c#

I'm using the code below to try and save to the local setting in Windows Mobile 8 using c#.

 public void SaveInfo(string key, string value)
        {
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(key))
            {
                if (ApplicationData.Current.LocalSettings.Values[key].ToString() != null)
                {
                    // do update
                    ApplicationData.Current.LocalSettings.Values[key] = value;
                }
            }
            else
            {

                // do create key and save value, first time only.
                ApplicationData.Current.LocalSettings.CreateContainer(key, ApplicationDataCreateDisposition.Always);
                if (ApplicationData.Current.LocalSettings.Values[key] == null)
                {
                    ApplicationData.Current.LocalSettings.Values[key] = value;
                }
            }
        }

When calling the code the debug crashes with the exception below:

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll

Any idea

Upvotes: 0

Views: 155

Answers (1)

Dan
Dan

Reputation: 2344

I needed to use the IsolatedStorageSettings feature, as below:

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;


            settings["test"] = urlText.Text;
            settings.Save();

Upvotes: 0

Related Questions