2012-06-27 61 views
0

我嘗試了MonoTouch/MonoAndroid,一切都在 ,直到我調用IsolatedStorageFile.GetFileNames(string)函數。 參數是「Foo/Foo1/*」。結果是沒有消息的SecurityException。MonoTouch/MonoDroid上的IsolatedStorage.GetFileNames失敗

目錄「Foo/Foo1」存在,因爲它剛剛被發現使用IsolatedStorageFile.GetDirectoryNames()調用。

我確定了單聲道音源此位拋出異常(在IsolatedStorageFile.cs):

DirectoryInfo[] subdirs = directory.GetDirectories (path); 
// we're looking for a single result, identical to path (no pattern here) 
// we're also looking for something under the current path (not 
outside isolated storage) 
if ((subdirs.Length == 1) && (subdirs [0].Name == path) && (subdirs[0].FullName.IndexOf(directory.FullName) >= 0)) { 
    afi = subdirs [0].GetFiles (pattern); 
} else { 
    // CAS, even in FullTrust, normally enforce IsolatedStorage 
    throw new SecurityException(); 
} 

我不能踏進去使用調試器,所以我不知道爲什麼 條件假。這發生在iOS和Android上。很久以前有一個 類似問題記錄在 http://www.digipedia.pl/usenet/thread/12492/1724/#post1724,但那裏 沒有答覆。

相同的代碼在Windows Phone 7上可以正常工作(使用\用於路徑分隔符)。

有沒有人有任何想法可能導致它?目錄名稱是 大寫的問題嗎?

+0

經過一番搜索,我有一些問題給你。您是否啓用了快速部署?在使文件夾具有不正確的權限之前,存在一些問題:http://mono-for-android.1047100.n5.nabble.com/IsolatedStorage-or-OpenFileOutput-td5116430.html您是否確定要使用設備的內部存儲器?這通常只用於緩存少量數據。更大的東西應該放在SD卡上。 IsolatedStorage僅指向手機的內部存儲器。 – Cheesebaron

+0

@Cheesebaron我不知道快速部署,今天晚些時候我有機會的時候我會檢查它。你認爲這可能導致異常嗎? – kaalus

+0

由於應用程序的已創建文件夾的權限錯誤,因此之前已經看到這樣做。解決方案是從設備中刪除應用程序,禁用快速部署並再次嘗試。看看是否有幫助。 – Cheesebaron

回答

1

這是Mono中的一個錯誤。 IsolatedStorage不適用於連續包含多個目錄的路徑(如Foo/Foo1/*)

我將Mono的GetFileNames()方法的代碼複製到我的項目中,以便我可以調試它。我發現,這個問題是在這種情況下的第二項(IsolatedStorageFile.cs:846):

if ((subdirs.Length == 1) && (subdirs [0].Name == path) &&(subdirs[0].FullName.IndexOf(directory.FullName) >= 0)) { 
    afi = subdirs [0].GetFiles (pattern); 
} else { 
    // CAS, even in FullTrust, normally enforce IsolatedStorage 
    throw new SecurityException(); 
} 

例如,當傳遞到GetFileNames()路徑是「富/酒吧/ *」,子目錄[0 ] .Name將爲「Bar」,而路徑將爲「Foo/Bar」,並且條件將導致異常失敗。

+0

如果你還沒有做到這一點,如果你把它作爲一個錯誤提交,如果它還沒有出現在錯誤跟蹤器中,那將是非常棒的:https://bugzilla.xamarin.com / – Cheesebaron