我有一個用於注入到我的服務的Windows Phone的IMvxFileStore實現的實例。在IsolatedStorageFileStream上不允許操作。當使用MvvmCross文件插件
讓我們說,我想存儲在位於AppSettings的文件設置\的UserProfiles \ profile1.txt
使用該文件的插件,我首先調用API EnsureFolder存在,傳遞的完整路徑我的個人資料設置文件appsettings \ userprofiles \ profile1.txt以確保此文件夾已創建並存在。
只是爲了理智,我檢查以確保該文件夾是使用FolderExist API創建的。至少現在至少返回true。
的代碼看起來是這樣的:
private string GetStorageItemFileName(string filename)
{
Guard.ThrowIfNull(string.IsNullOrWhiteSpace(BaseDirectory), Messages.RepositorBackingStoreIsNull);
filename = _fileStore.PathCombine(BaseDirectory, filename);
_fileStore.EnsureFolderExists(filename);
if (_fileStore.FolderExists(filename))
{
// what do do????
}
return filename;
}
然而,當我試圖將內容寫入使用將writeToFile API文件,通過在文件名從上面的方法和一些返回的字符串,如下
try
{
_fileStore.WriteFile(filename, content);
}
catch (Exception ex)
{
Logger.Error(ex);
}
,我得到以下異常:
System.IO.IsolatedStorage.IsolatedStorageException被捕獲
HResult = -2146233264 Message =不允許在 IsolatedStorageFileStream中執行操作。源= mscorlib程序堆棧跟蹤: 在System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(字符串路徑, 的FileMode模式,FileAccess的訪問,文件共享份額,緩衝區大小的Int32, IsolatedStorageFile ISF) 在System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor (字符串路徑, 的FileMode模式,IsolatedStorageFile ISF) 在Cirrious.MvvmCross.Plugins.File.WindowsPhone.MvxIsolatedStorageFileStore.WriteFileCommon(字符串 路徑,Action`1 streamAction) 在Cirrious.MvvmCross.Plugins.File.WindowsPhone.MvxIsolatedStorageFileStore。 WriteFile(字符串 路徑,字符串內容) at TrackuTransit.Core.Services.DataStore.StorageItemFileRepository.Put(String filena我,StorageItem數據)的InnerException:
我的開發環境的設置如下: - 表面臨3 - 的Visual Studio 2013社區 - 的Windows Phone 8.1 SDK和模擬器 - MvvmCross 3.0.0.4。 (是的,這是舊的,將在MVP後更新)。
在我深入研究MvvmCross代碼庫之前,任何有關我在這裏可能會做錯什麼的想法的人?
在這一點上很難說,因爲你是在這樣一箇舊版本。我會盡力讓項目達到最新和最好的狀態,因爲它可能已經被照顧好了。這將刺激你,因爲你將需要改變你的PCL配置文件爲259或兼容。 – PkL728
還要確保您沒有多個線程同時訪問隔離存儲。如果你確實需要將開放文件調用的最後一個參數設置爲System.IO.FileShare.ReadWrite或者你需要的任何權限。 – PkL728
這是我希望不會聽到的答案:),因爲此時升級解決方案(包括28個項目)將讓我回到至少幾天。我懷疑這是一個跨線程問題。 –