Monthly Archives: May 2015

Converting an existing Windows Store App to a new one

I recently decided to create a new Windows Store app, that was very similar to one that I’d already created; I decided that it would be a quick task to adapt the existing application and publish under a new name.

Since this is not completely pain free, here are some of the errors and fixes.

The first thing I did was to change the Package name, under the assumption that this would need to be associated with my new application:

StorePackageManifest

When I did so, I got the following error:

The Name attribute of the Identity element in the app manifest must have the Package name value of the selected app: …

I then tried selecting a new test certificate; which results in the following error:

The Publisher attribute of the Identity element in the app manifest must have the value of the Publisher ID value from your developer account: CN=1AAAAAAA-XXXX-YYYY-XXXX-ZZZZZZZZZZZZZZ

Both of these fields are generated when publishing to the store, and I finally realised that the fix was to delete the XML file:

StoreAssociation.xml

When you publish this to the store, these fields will be re-populated, and the StoreAssociation.xml file regenerated.

Serialise and De-Serialise Helpers for ObservableCollection

I recently came across a need to serialise and de-serialise an ObservableCollection from an MVVMCross application. To achieve this, I created a couple of helper methods which I’d like to share.

Both use the MVVM Cross File plug-in.

Serialise

        public static void Serialise<T>(ObservableCollection<T> collection, string fileName)
        {
            var file = Mvx.Resolve<IMvxFileStore>();
            var fileData = file.OpenWrite(fileName);

            DataContractSerializer serializer = new
                        DataContractSerializer(typeof(ObservableCollection<T>));
            serializer.WriteObject(fileData, collection);
            fileData.Flush();
        }

De-serialise

        public static ObservableCollection<T> DeSerialise<T>(string fileName)
        {
            var file = Mvx.Resolve<IMvxFileStore>();
            if (!file.Exists(fileName))
                return null;

            var fileData = file.OpenRead(fileName);
            if (!fileData.CanRead || fileData.Length == 0)
                return null;

            DataContractSerializer serializer = new
                        DataContractSerializer(typeof(ObservableCollection<T>));

            ObservableCollection<T> data = (ObservableCollection<T>)serializer.ReadObject(fileData);
            return data;
        }

The Serialise method can be wrapped in an extension method, too:

        public static void Serialise<T>(this ObservableCollection<T> collection, string fileName)
        {
            Helpers.SerialiseHelper.Serialise(collection, fileName);
        }

Obviously, the `DeSerialise` cannot, as it would change the object that you are extending.