C# IsolatedStorage ArgumentNullException

C# IsolatedStorage ArgumentNullException,c#,isolatedstorage,C#,Isolatedstorage,我看不出这里有什么问题: 建造商: IsolatedStorageFile isf; public FileManagement() { isf = IsolatedStorageFile.GetUserStoreForApplication(); } 保存文件时: public bool saveCredentials(String username, String userpass) {

我看不出这里有什么问题:

建造商:

IsolatedStorageFile isf;
        public FileManagement()
        {
            isf = IsolatedStorageFile.GetUserStoreForApplication();
        }
保存文件时:

   public bool saveCredentials(String username, String userpass)
        {
            bool res = false;

            StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("usercred.custom",
                FileMode.Create, FileAccess.Write, isf));
            writeFile.WriteLine(username);
            writeFile.WriteLine(userpass);
            res = true;

            return res;
        }
当我试图阅读它们时:

public String readUsername()
    {
        String username = "";
        IsolatedStorageFileStream fileStream = isf.OpenFile("usercred.custom", FileMode.Open, FileAccess.Read);
        StreamReader reader = new StreamReader(fileStream);
        username = reader.ReadLine();

        return username;
    }
读取返回空值


我试图保存一个文件并向其中写入一些内容,但不知何故它不起作用。

您必须关闭流。请在返回之前添加reader.Close()、writefile.Close()和fileStream.Close(),然后重试。

Protip:如果您告诉我们它是如何工作的,我们将告诉您如何修复它。感谢您的提示。我现在编辑了它。请确保使用.Close()关闭所有流,然后重试。