【问题标题】:Why is my code throwing an IOException on zip extract?为什么我的代码在 zip 提取时抛出 IOException?
【发布时间】:2017-11-22 16:29:53
【问题描述】:

我正在使用 VB.Net 在 Windows CE 应用程序上使用 DotNetZip 库(紧凑的框架版本)。这似乎以前在 CE 5.0 上有效;问题出在 CE 6.0 上。异常对象的消息只是“发生了 IOException”(不是很具体,是的),当我尝试从 InnerException 获取消息时,它本身会引发 NullReferenceException。

更新:当 zip 文件包含 exe 文件时会发生错误,文本文件没有问题。

更新(再次):问题不在于 Zip 库,而在于 exe(被复制的那个)。我仍在寻找为什么它“正在使用”。 GetProcesses (OpenNetCF) 不在列表中。其他 exe,尽管之前运行过,但可以被覆盖。不是这个,不是以前已经运行过的。

代码如下:

Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
                Dim f As ZipEntry
                For Each f In zip1
                    f.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
                Next
            End Using

这是堆栈:

IOException

   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, 

String msgPath)
   at System.IO.FileStream..ctor(String path, FileMode mode)
   at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password)
   at Ionic.Zip.ZipEntry.Extract(String baseDirectory, ExtractExistingFileAction extractExistingFile)
   at updateMpad3.Form1.Timer1_Tick(Object sender, EventArgs e)
   at System.Windows.Forms.Timer._WnProc(WM wm, Int32 wParam, Int32 lParam)
   at System.Windows.Forms.ApplicationThreadContext._InternalContextMessages(WM wm, Int32 wParam, Int32 lParam)
   at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
   at System.Windows.Forms.Application.Run(Form fm)
   at updateMpad3.Form1.Main()

【问题讨论】:

  • 你能添加IOException的Message属性的值吗?
  • 它只是说“发生了IOException”。 InnerException 中没有任何内容。我发现当 zip 包含 .exe 文件时会发生错误。当它只是一个文本文件时什么都没有。
  • 您可以尝试从您的应用程序中向Path.Combine(TargetDir, "test.exe") 写入一些虚拟数据吗?因为这可能不是特定于该 zip 库的。
  • @Yves 不,我的意思是让您的应用程序将一些虚拟数据写入目标路径以查看是否有效 - 也许问题与 zip 库无关(因为堆栈跟踪表明它在System.IO.FileStream..ctor(...))。例如,该文件可能正在使用中。
  • 不,除了它运行之外,我想不出任何其他原因。作为一种解决方法,您可以重命名文件(在它运行时允许的),但您最终会在系统上得到一个.old 文件。

标签: vb.net compact-framework ioexception


【解决方案1】:

已修复。我在我的文档中提取,重命名/移动要覆盖的文件,并将提取的文件复制到 Program Files(替换的 exe 应该在的位置)。

不过,我不确定是什么原因造成的。没有什么可以覆盖那个特定的 exe。 DotNetZip 无法直接提取到该特定 exe 的文件夹(即使重命名它;其他 exe 工作正常),但 File.Copy 工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 2012-09-21
    • 1970-01-01
    • 2013-11-09
    相关资源
    最近更新 更多