以下代码似乎偶尔会产生此stacktrace。当在内部FileStream对象上调用dispose方法时,它似乎正在框架内发生?对我来说似乎是个 bug ,有什么想法吗?

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");
    }
}

最佳答案

如果我不得不猜测,我认为您可能由于在处理Flush()调用中的底层FileStream期间发生隐式ReadAllText而陷入竞争状态。

(注意:不在单声源的前面,因此无法确认确切的行为)

是否有可能:

  • 您要替换/重新打开/等。另一个线程中的相同文件路径?
  • 是在另一个线程之后还是在另一个线程中删除该路径?
  • 否则无法访问检查的路径? (是否正在卸载文件共享?)
  • 关于c# - MonoTouch File.ReadAllText在内部FileStream.Dispose()上引发异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9589704/

    10-13 09:52