5

I am busy developing an additional module for an existing C# (4.0) application that uses Ionic Zip library to manage the data. In my module I need to load data from zip files, manipulate them, and write back again. My routine runs OK in Unit Tests, but when called from within the host application, it throws an exception reading "The process cannot access the file because it is being used by another process". This happens at a point when I try to call the Save() function of the Zip archive.

I checked which process actually locks the file, and it happens to be the application itself. Therefore I conclude that there might be some kind of interference with the host program: e.g. a file stream opened at some place and not closed. (BTW, are there some smart techniques to look after such places?)

What puzzles me is whether those ZipFile's of Ionic really lock / unlock files when dealing with files, as in the following code piece:

ZipFile zf  = new ZipFile("test01.zip");
zf.Save();

// FileSystemTools.WhoIsLocking is a utility showing a list pf processes
// holding access to a given file
// Similar to http://stackoverflow.com/questions/1304/how-to-check-for-file-lock/20623302#20623302

List<Process> processes = FileSystemTools.WhoIsLocking("test01.zip");
Assert.That(processes.Count == 1);

zf.Dispose();
processes   = FileSystemTools.WhoIsLocking("test01.zip");
Assert.That(processes.Count == 0);

After Save() the number of locking processes is 1 (the running process itself), but after Dispose() there are none, which attests that Ionic.ZipFile obviously holds some file streams internally and manages them somehow. At other places, however, Dispose() has no effect: the number of locking process is not decremented. Iconic.Zip documentation is scarce and nconvincing.

dandan78
  • 13,328
  • 13
  • 64
  • 78
  • Are you sure this `ZipFile` is from the .Net framework? It does seem to bee an static class: https://msdn.microsoft.com/de-de/library/system.io.compression.zipfile%28v=vs.110%29.aspx In addition: you may have to `.close()`the ZipFile! Dispose normaly closes it aswell. – Alex H Jan 14 '16 at 10:09
  • Hi Alex H, you are mentioning ZipFile from System.IO.Compression whereas I mean Ionic.Zip.ZipFile (e.g. http://dotnetzip.herobo.com/DNZHelp/Index.html) - I simply must use this one. –  Jan 14 '16 at 11:24

0 Answers0