0

I have an issue when reading from an xml file with the object Friend in it!

file.exist() returns true but when he opens storage, an exception is thrown!

public static async Task<List<Friend>> Load<Friend>(string file)
{           
    IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
    List<Friend> friend = Activator.CreateInstance<List<Friend>>();

    if (storage.FileExists(file))
    {
        IsolatedStorageFileStream stream = null;
        try
        {
            stream = storage.OpenFile(file, FileMode.Open);
            XmlSerializer serializer = new XmlSerializer(typeof(List<Friend>));

            friend = (List<Friend>)serializer.Deserialize(stream);
        }
        catch (Exception)
        {
        }
        finally
        {
            if (stream != null)
            {
                stream.Close();
                stream.Dispose();
            }
        }
        return friend;
    }
    return friend;
}
GC268DM
  • 403
  • 7
  • 15

1 Answers1

1

Your method doesn't use any asynchronous calls, so it shouldn't be flagged async:

public static List<Friend> Load(string file) 
{

The compiler will warn you because you marked the method asynchronous, and made it return Task<T>, but you don't call and await any asynchronous methods, so it will always run synchronously.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • Thanks, that removed the warning! But I still get the message: "System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream" – GC268DM Oct 17 '13 at 16:24
  • @GC268DM See http://stackoverflow.com/questions/8415979/operation-not-permitted-on-isolatedstoragefilestream-error for more details – Reed Copsey Oct 17 '13 at 16:35