0
votes

I have this Isolated Storage Function to write into storage :

public static void WriteIsolatedStorage(object ObjectToStore, StorageType Key)
{

    using (var storage = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
    using (var storageFile = storage.CreateFile(Key.ToString()))
    {
        var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(string));
        switch (Key)
        {
            case StorageType.UserCredentials:
                xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFUserCredentials));
                break;
            case StorageType.BackgroundAgentUserCredentials:
                xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFUserCredentials));
                break;
            case StorageType.UserProfile:
                xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFUser));
                break;
            case StorageType.InboxItems:
                xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection<dmWFInboxItem>));
                break;
            case StorageType.InboxTileItems:
                xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection<dmInboxTileInfo>));
                break;
            case StorageType.DocumentHeaders:
                xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection<dmWFDocumentHeader>));
                break;
            case StorageType.SearchCache:
                xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(List<List<dmWFDocumentHeader>>));
                break;
            case StorageType.FacebookProfile:
                xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmFBUserProfile));
                break;
            case
                StorageType.BaseUrl:
                xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFURLSetting));
                break;
            default:
                break;
        }
        xmlSerializer.Serialize(storageFile, ObjectToStore);
    }

}

And then here is my function to get from this storage :

public static dmWFURLSetting GetBaseUrl(StorageType Key)
{
    try

    {

        using (var storage = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (var storageFile = storage.OpenFile(Key.ToString(), System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite))
            {
                dmWFURLSetting result = new dmWFURLSetting();
                var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFURLSetting));
                return (dmWFURLSetting)xmlSerializer.Deserialize(storageFile);
            }
        }

    }
    catch (Exception)
    {
        return null;
    }

}

okay and then here is how i call these methods fromm front end and then viemodel, i am using mvvm fr this phone app. Frontend call :

public string URL = (WorkflowBase.BaseURL != null ? WorkflowBase.BaseURL.ToString() : "");

here is the public property in backend :

public static string BaseURL = AccTech.WP8.Helpers.IsolatedStorage.GetBaseUrl(Helpers.IsolatedStorage.StorageType.BaseUrl).BaseUrl.ToString();

okay so here comes the weird part, i know when i start the emulator after being closed completely the isolated storage(cache) is completely clean so if this function is called i will get a Null return... as you can see in my frontend call i made an inline if that if i get a null value, then make it "". so here is the error that i get when i run. PS: if i make the URL static the app works enter image description here

okay and here is the error i get when i try to step through the whole process :

enter image description here

i am physically unable to get this working i have tried everything google offers... but nothing happens , if someone can please give me an answer i will be delighted.

if you need more data or info please let me know

2
Check if dmWFURLSetting has the proper attributes for (de)serialization and a public constructor.kindasimple

2 Answers

0
votes

WorkflowBase.BaseURL != null , this workflowbase class it was pointing to never changed the public variable to the data it got so that is why the error occoured! .

so yeah noob mistake of the week! :P

0
votes

Yes i also getting this type of exception.But region behind this exception is your isolated storage not contain key which you want to access so if any cash access isolated storage first check contain.In Visual studio also check how many keys in isolated storage by using break point in the isolated storage object.