1
votes

i was trying to develop a universal app for Windows 8.1 in C# using Visual Studio 2015. for testing i saved some text in RoamingSettings in Windows project then while trying to read that text in Windows Phone Project the app crashes due to a "NullRefrenceException".. Here is my Code

in Windows Project :

Windows.Storage.ApplicationDataContainer RoamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

RoamingSettings.Values["USERNAME"] = userNameInput.Text;

in Windows Phone Project :

Windows.Storage.ApplicationDataContainer RoamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;

myTextBlock.Text = RoamingSettings.Values["USERNAME"].ToString();

as i mentioned the Windows Phone app crashes in both the emulator and the physical phone, did i write the required code for this feature ? is the Roaming Settings/Folder is the place which stores universal apps data ?

Thanks for your time

1

1 Answers

2
votes

First of all, for roaming settings to work, you need to be logged in on both devices with the same Microsoft account.

These settings are not instantly synced so you can't test them on your phone device immediately after you update the setting on your Windows device.

Also make sure you check whether the value you are trying to retrieve is not null:

if(RoamingSettings.Values.ContainsKey("USERNAME"))
{
    myTextBlock.Text = RoamingSettings.Values["USERNAME"].ToString();
}

After this you should not get any NullReferenceException, but when the value is synced sometime later, the code in the if block will eventually execute.