2012-03-06 67 views
6

以下代碼似乎偶爾會產生此堆棧跟蹤。它看起來像在內部FileStream對象上調用dispose方法時發生在框架內?看起來像一個錯誤,對我來說,有什麼想法?MonoTouch File.ReadAllText拋出內部FileStream.Dispose異常()

var previousVersion = long.Parse(File.ReadAllText(Paths.VersionFile)); 

堆棧跟蹤:

System.IO.IOException: Invalid parameter 
     at System.IO.FileStream.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0 
     at System.IO.Stream.Close() [0x00000] in <filename unknown>:0 
     at System.IO.StreamReader.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0 
     at System.IO.TextReader.Dispose() [0x00000] in <filename unknown>:0 
     at System.IO.File.ReadAllText (System.String path) [0x00000] in <filename unknown>:0 
     at CatalystHD.Shared.BaseLoginController.CheckIfFirstRunThisVersion() [0x00000] in <filename unknown>:0 
     at CatalystHD.Shared.BaseLoginController.ViewDidLoad() [0x00000] in <filename unknown>:0 
     at MonoTouch.UIKit.UIViewController.get_View() [0x00000] in <filename unknown>:0 
     at CatalystHD.IPad.RootViewController.AnimateTo (MonoTouch.UIKit.UIViewController aController, UIViewAnimationTransition transition) [0x00000] in <filename unknown>:0 
     at CatalystHD.IPad.RootViewController.Logout (Boolean timeout) [0x00000] in <filename unknown>:0 
     at CatalystHD.IPad.NotebookSelectionController.logoutButton_Clicked (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0 
     at MonoTouch.UIKit.UIBarButtonItem Callback.Call (MonoTouch.Foundation.NSObject sender) [0x00000] in <filename unknown>:0 
     at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00000] in <filename unknown>:0 
     at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in <filename unknown>:0 
     at CatalystHD.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0 

編輯 VersionFile路徑抓住這樣:

public static string VersionFile { 
    get { 
     var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 
     return Path.Combine(path, "version.dat"); 
    } 
} 
+0

什麼是傳遞與'Paths.VersionFile'? – 2012-03-06 18:29:59

+0

@ DanielA.White查看編輯 – 2012-03-06 18:35:07

+1

我們需要更多關於您應用程序的上下文,例如,我可以在沒有任何問題的情況下在循環中運行代碼10000x,因爲其他內容必須有所不同。像什麼時候該文件創建,更新,刪除?由任何不同的線程?它發生在設備,模擬器上嗎? ...和所有版本號。 – poupou 2012-03-06 19:16:49

回答

0

如果我猜的話,我想你可能會運行到比賽狀態由於隱含Flush()發生在處置發動機罩FileStream在那ReadAllText叫。

(警告:不是在單聲道音源前面,所以無法確認確切的行爲)

有沒有可能是:

  • 您正在更換/重啓/等。另一個線程中的文件路徑相同?
  • 在其他線程之後立即刪除該路徑?
  • 否則失去對檢查路徑的訪問權限? (文件共享卸載?)