StorageHelper NuGet package

UPDATE June 22, 2014: Version 1.1.4 of StorageHelper is now available through NuGet, adding settings APIs for Windows Store (Windows 8.1, Windows Phone 8.1 and Universal) apps. Please note that there was a change in namespaces to clean things up and Windows Phone 7.1 and Windows 8.0 support was dropped (you can still install 1.1.3 for those projects. On the upside: I’ve open-sourced the package through GitHub, so you can contribute if needed!

If you’ve taken a look at any of my starting templates (Windows Phone or Windows) or at my Windows Phone RSS Reader app template, you’ve probably noticed the StorageHelper class in there. It’s a convenient way of abstracting some of the logic of loading, saving and removing data from either the application’s state or persistent storage. I’ve now extracted that class and made it available in a NuGet package, so it’s easier to re-use in projects, without having to copy a class file over.

Installing the package

You can either use the Package Manager Console or the NuGet GUI in Visual Studio to install the package. In the Package Manager Console, simply use the following command:

The package will automatically add the proper library reference according to the type of project you’re adding it to (Windows Phone 7, Windows Phone 8 or Windows 8). If you’re using the NuGet GUI in Visual Studio, simply search for StorageHelper and install it that way.


Windows Phone 7

As Windows Phone 7 does not have native support for the async/await pattern, the functionality in StorageHelper is also synchronous in nature. The following methods are available on Windows Phone 7:

The first three methods will save, load or delete an object from the PhoneApplicationService.Current.State dictionary, meaning it will only be there as long as your app is loaded into memory. A good use of these methods is when implementing the behavior that will be used when your app is tombstoned, for example to store form data temporarily to be restored when the user navigates back to the app.

The last three methods will save, load or delete an object from the IsolatedStorageSettings.ApplicationSettings dictionary, which will be persisted on the device. Use these methods when saving settings or data that will need to be accessible between sessions in the app.

Windows Phone 8

With the release of Windows Phone 8, we got SDK support for the async/await pattern. The methods available on Windows Phone 8 are largely the same as on Windows Phone 7, with the exception of async/await support for the persistent storage methods:

These methods are only available to be used asynchronously, but use the await keyword from the async/await pattern to make your life easier when programming asynchronously.

Windows 8

On Windows 8, the storage methods are limited to the persistent storage methods only, with the functionality (and code) being the same as on Windows Phone 8. The only difference here is that by default, StorageHelper will save, load and delete from the ApplicationData.Current.RoamingFolder folder, meaning everything will be persisted to the cloud and accessible on every device for a particular user. You can also opt to save, load and delete locally of course, which can be done with the overloads for each method:

Hopefully StorageHelper will help you manage the storage needs of your apps more easily and as always, let me know your feedback, comments and suggestions in the comments below or reach me on Twitter!

Pin It

10 thoughts on “StorageHelper NuGet package

  1. Pingback: ReviewNotifier NuGet package - Rajen's Technical Tidbits

  2. Pingback: Windows Store Developer Links – 2013-08-27 | Dan Rigby

  3. Pingback: Windows starting template (October 2013) - Rajen's Technical Tidbits

  4. Pingback: Build apps for a device - Rajen's Technical Tidbits

  5. Hi i have used your StorageHelper and it really helps, but i wanted to upload now an app with StorageHelper which uses Storage.SaveAsync and the store says :

    2011: The background agent can’t use Microsoft.Phone.Shell.PhoneApplicationService::get_State, which assembly StorageHelper.WindowsPhoneSilverlight.dll is trying to use. Update your file and then try again.

    2011: The background agent can’t use Microsoft.Phone.Shell.PhoneApplicationService, which assembly StorageHelper.WindowsPhoneSilverlight.dll is trying to use. Update your file and then try again.

    2011: The background agent can’t use Microsoft.Phone.Shell.PhoneApplicationService::get_Current, which assembly StorageHelper.WindowsPhoneSilverlight.dll is trying to use. Update your file and then try again.

    Can this be fixed or overriden somehow so i can use it?

    • Hi Dino, that’s a fair point, thanks. I haven’t tested it with a background agent. How you can fix it is download the source from and remove the Save State, Load State and Delete State code from it (line 29-84). Feel free to add an additional conditional compilation symbol and update the code to make it work in a background agent. Looking forward to the pull request 🙂

      • Thx for the fast response, i’m new to github and such things compiling this i mean. What exactly i have to do after the download of the github files?! You can alos reach my on my email if this is faster…

      • Hi Rajen, i have now removed it on Github and posted also a description of the removal, now its waiting your apporval i think?! do you see it? and what follows now?

        • Hi Dino, for now, just download the source and compile it locally when you remove the lines. Simply removing it from my GitHub repo will not work, as it will break functionality in normal (foreground) apps. I’ll update the library when I have time, but for now just make a clone of it and compile it locally for your project.

Leave a Reply

Your email address will not be published. Required fields are marked *