I get an error while writing data to a file. Unable to access disposable object. Object Name: MS.internal.InternalMemorystream

This was the code:

 public static void SaveFile(Stream stream, string fileName = "")
    {
        using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
        {
            IsolatedStorageFileStream fs = file.CreateFile(fileName);

            var filesize = stream.Length;
            var getContent = new byte[(int)filesize];
            stream.Read(getContent, 0, (int)filesize);
            fs.Write(getContent, 0, (int)filesize);

            fs.Close();
        }
    }
+3
source share
1 answer

There is nothing wrong with the code you posted. There is an error in the code that you use to call this function. Most likely you are going through Stream, which was installed prematurely.

+1
source

Source: https://habr.com/ru/post/1746315/


All Articles