Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:28:23+00:00 2026-06-09T17:28:23+00:00

I’m attempting to store a List (where Show is my class that implements IXmlSerializable)

  • 0

I’m attempting to store a List (where Show is my class that implements IXmlSerializable) to the local isolated storage. I’m using the code from this page:
http://metrostoragehelper.codeplex.com/
I’ve implemented the change suggested in the Issues section.
I am using the following code to add a Show object when it is clicked from an item list.

private async void addShowButton_Click_1(object sender, RoutedEventArgs e)
    {
        var isoStorage = new StorageHelper<List<Show>>(StorageType.Local);

        List<Show> currentShows = await isoStorage.LoadASync("myShowsEx");
        if(currentShows == null) {
            currentShows = new List<Show>();
        }

        currentShows.Add(currentShow);

        isoStorage.SaveASync(currentShows, "myShowsEx");


        //Read it back, for debugging to check if it has been added properly. 
        List<Show> currentShowsRB = await isoStorage.LoadASync("myShowsEx"); //Exception here

    }

The first show is added perfectly fine and it shows up in the currentShowsRB List. When a second item is clicked and the method above invoked an exception occurs on the last LoadAsync call: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
How can I get around this to access the local data store for multiple calls?

Below is also the relevant code from the StorageHelper:

public async void SaveASync(T Obj, string FileName)
    {

        FileName = FileName + ".xml";
        try
        {
            if (Obj != null)
            {
                StorageFile file = null;
                StorageFolder folder = GetFolder(storageType);
                file = await folder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);

                using (var writeStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    Stream outStream = Task.Run(() => writeStream.AsStreamForWrite()).Result;
                    serializer.Serialize(outStream, Obj);
                    //writeStream.Dispose(); //Added and we get UnauthorizedAccessException
                    // outStream.Dispose(); //Added ObjectDisposedException caught in catch statement below
                }
            }
        }
        catch (Exception)
        {
            throw;
        }
    }
    public async Task<T> LoadASync(string FileName)
    {
        FileName = FileName + ".xml";
        try
        {
            StorageFile file = null;
            StorageFolder folder = GetFolder(storageType);
            file = await folder.GetFileAsync(FileName);
            using (var readStream = await file.OpenAsync(FileAccessMode.Read))
            {
                Stream inStream = Task.Run(() => readStream.AsStreamForRead()).Result;
                inStream.Position = 0;
                return (T)serializer.Deserialize(inStream);
            }
        }
        catch (FileNotFoundException)
        {
            //file not existing is perfectly valid so simply return the default 
            return default(T);
            //throw;
        }
        catch (Exception)
        {
            //Unable to load contents of file
            throw;
        }
    }

The writeStream.Dispose() line I added in, but even when this is included I get the same error message of Access is Denied. If I also include the outStream.Dispose() line then I get a ObjectDisposedException being caught in the catch statement right below. Is there something else I should be doing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:28:25+00:00Added an answer on June 9, 2026 at 5:28 pm

    You are not waiting for the SaveAsync to finish, trying to Load when the Save is still in progress. Change it to:

    //isoStorage.SaveASync(currentShows, "myShowsEx");
    await isoStorage.SaveASync(currentShows, "myShowsEx");   
    
    List<Show> currentShowsRB = await isoStorage.LoadASync("myShowsEx"); 
    

    Edit, awaiting on void is a standard problem.
    The quick fix is :

     await TaskEx.Run(() => isoStorage.SaveASync(currentShows, "myShowsEx"));
    

    But you can also move the TaskEx.Run() inside SaveASync(). And given a name that ends with Async, it should not be void but:

    Task SaveASyncT Obj, string FileName)
    { 
        return TaskEx.Run() => { .... }
    }
    

    I don’t believe there is an async version of Serialize, so it stays at TaskEx.Run() .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.