Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DotNetZip库:创建拆分存档-System.UnauthorizedAccessException_C#_Dotnetzip - Fatal编程技术网

C# DotNetZip库:创建拆分存档-System.UnauthorizedAccessException

C# DotNetZip库:创建拆分存档-System.UnauthorizedAccessException,c#,dotnetzip,C#,Dotnetzip,我们将zip.MaxOutputSegmentSize设置得足够高,这样就只有一个zip文件可以工作。 一旦我限制了MaxOutputSegmentSize,在一个分割文件达到其最大大小后,我就会出现此错误-当我有一个像20MB这样的值时,它总是出现在文件“.z02”的末尾,如果该值较小,它也可能在以后的某个文件中出现 如果使用zip.ziperroAction=ziperroAction.Skip或.Retry,则会得到System.ObjectDisposedException 这里可能有什

我们将zip.MaxOutputSegmentSize设置得足够高,这样就只有一个zip文件可以工作。 一旦我限制了MaxOutputSegmentSize,在一个分割文件达到其最大大小后,我就会出现此错误-当我有一个像20MB这样的值时,它总是出现在文件“.z02”的末尾,如果该值较小,它也可能在以后的某个文件中出现

如果使用zip.ziperroAction=ziperroAction.Skip或.Retry,则会得到System.ObjectDisposedException

这里可能有什么问题,或者这是DotNetZip库中的一个Bug

ZipFile zip = new ZipFile(backupPath + "Backup.zip");
            zip.MaxOutputSegmentSize = maxSize;
            //zip.TempFileFolder = @"D:\Backup\Temp"; //seems not to make any difference

            zip.Comment = "Backup created at " + System.DateTime.Now.ToString("G");
            zip.AddFile(dbBackup.FullName,"Database");
            zip.AddDirectory(physicalAppPath,"Application");

           zip.AddDirectory(mailArchivePath,"MailArchive");
           zip.Save(); //Exception occurs here
堆栈跟踪:

bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
bei System.IO.File.Move(String sourceFileName, String destFileName)
bei Ionic.Zip.ZipSegmentedStream.TruncateBackward(UInt32 diskNumber, Int64 offset)
bei Ionic.Zip.ZipEntry.Write(Stream s)
bei Ionic.Zip.ZipFile.Save()
bei MyProject.Configuration.Backup.BackupLogic.Backup(Boolean monthly) in D:\projects\MyProject.Configuration\Backup\BackupLogic.cs:Zeile 100.
bei MyProject.Configuration.Backup.BackupLogic.ScheduledBackup() in D:\projects\MyProject.Configuration\Backup\BackupLogic.cs:Zeile 42.
bei MyProject.Configuration.BackupTimer.CreateThread(Object parameters) in D:\projects\MyProject.Configuration\BackupTimer.cs:Zeile 60.
bei System.Threading.ExecutionContext.runTryCode(Object userData)
bei System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart(Object obj)
使用ZipErrorAction.Skip的异常和StackTrace:

ObjectDisposed Exception was unhandled: Auf eine geschlossene Datei kann nicht zugegriffen werden. (Could not access an closed file)

bei System.IO.FileStream.get_Position()
bei Ionic.Zip.ZipEntry.Write(Stream s)
bei Ionic.Zip.ZipFile.Save()
...
目标文件夹上带有筛选器的Process Monitor未显示任何可疑内容:(在本例中,创建了3个拆分文件,然后发生异常)


问题是在一个文件夹中有gzip文件(.gz带密码)-DotNetZip似乎无法拆分这些文件(7zip可以)。因此,当它到达填充了这些gzip文件的.zip文件的末尾时,就会发生异常

我现在使用了一种变通方法,因此我循环所有文件,计算总大小,并在每次达到最大大小时创建单个(未拆分)zip文件


DotNetZip的问题(Bug?)仍然存在。

DotNetZip的v1.9.1.5中有一个Bug,与分段归档有关。您使用的是什么版本?它是最新的1.9.1.8“这是DotNetZip v1.9的开发人员工具包。此包打包在Sat-08-06-2011-215945.06。”unauthorizedaccessexception是文件的。Move方法,可能意味着要写入的文件已经存在,并且已经在使用中(甚至可能由您自己的应用程序)或只读或特权,否则您无权在该目录中创建或删除文件。很难说这里出了什么问题,但我想DotNetZip社区可以帮助您,或者您可以尝试使用SysInternals Suite工具查看该文件夹中的文件操作,以查看调试过程中发生了什么。objectdisposedexception的stacktrace可能也会告诉我们一些事情,发布它。我在其中创建zip文件的文件夹是空的,除了zip.save()方法之外,没有其他方法可以对它起作用。所以DotNetZip应该自己创建这个写问题
12:35:25.6312905 PM w3wp.exe    5380    CreateFile  D:\Backup   SUCCESS Desired Access: Write Data/Add File, Synchronize, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, AllocationSize: n/a, Impersonating: NT-AUTORITÄT\IUSR, OpenResult: Opened
12:35:25.6319249 PM w3wp.exe    5380    CloseFile   D:\Backup   SUCCESS 
12:35:27.7507327 PM w3wp.exe    5380    CreateFile  D:\Backup   SUCCESS Desired Access: Write Data/Add File, Synchronize, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, AllocationSize: n/a, Impersonating: NT-AUTORITÄT\IUSR, OpenResult: Opened
12:35:27.7511904 PM w3wp.exe    5380    CloseFile   D:\Backup   SUCCESS 
12:35:32.9936509 PM w3wp.exe    5380    CreateFile  D:\Backup   SUCCESS Desired Access: Write Data/Add File, Synchronize, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, AllocationSize: n/a, Impersonating: NT-AUTORITÄT\IUSR, OpenResult: Opened
12:35:32.9941529 PM w3wp.exe    5380    CloseFile   D:\Backup   SUCCESS