3

I have a C# .NET (v4.6.2) WinForms app where I'm accessing a file that may/may not be a .zip archive that was created using System.IO.Compression. I have both System.IO.Compression and System.IO.Compress.FileSystem references in the project and referencing System.IO.Compression in the .cs file

I'm getting the error

"could not read file from disk. (Error: method not found: 'Void system.io.compression.zipfile.extensions.extractToFile(System.IO.Compression.ZipArchiveEntry, system.string)'"

It looks like the issue, based on the error, is in the ExtractToFile command, though I can't figure out where to start to fix this.

Below is the code for attempting to open the file as a .zip archive:

using (ZipArchive archive = new ZipArchive(File.OpenRead(zipPath), ZipArchiveMode.Read))
{
    foreach (ZipArchiveEntry entry in archive.Entries)
    {
        if (entry.FullName.EndsWith(".wco3", StringComparison.OrdinalIgnoreCase))
        {
            entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
        }
    }
    if (File.Exists(DestPath + DestFile))
    {
        Success = Succeeded;                                
    }
} 
Nkosi
  • 235,767
  • 35
  • 427
  • 472
Jeff S.
  • 33
  • 7
  • Are you sure this is the actual error? Because, this: `system.io.compression.zipfile.extensions` doesn't exist. The extension method Is found in `System.IO.Compression.ZipFileExtensions`. If you position the caret on the `ExtractToFile()` method and press F12, what happens? – Jimi Nov 26 '18 at 23:28
  • Jimi, it goes to the line public static void ExtractToFile(this ZipArchiveEntry source, string destinationFileName); under ZipFileExtensions [from metadata] – Jeff S. Nov 27 '18 at 00:08
  • So, the extension method does exist. Is the error reported just a typo, then? Also, the System.IO.Compress**ion**.FileSystem. Try: delete everything in the Project's `obj` sub-folder. The `.vs` folder in the Solution main directory, clean the Solution, rebuild the Solution. Verify you don't have any other extension method anywhere else that references the `ZipArchiveEntry` class. Or some other library you might have tested before, maybe. – Jimi Nov 27 '18 at 00:21
  • So I verified there are no other extension methods referencing the ZipArchiveEntry class and there aren't. I tried what you said and no change. I know there isn't a typo, as it works on 1 build, but not the platform that I need to deploy the WinForm app. – Jeff S. Nov 27 '18 at 01:31
  • Have you tested other compression libraries? Have you checked whether some references to *unknown* assemblies are still present in the Project(s) `References` or in the `[project].csproj` or `packages.config` files? – Jimi Nov 27 '18 at 01:38
  • @JeffS. you mentioned that code works fine on one PC but not on another. Most likely one of the PCs have the greater version of .NET (f.e. 4.6) and another lower (f.e. 4.0). Can you provide .NET Framework versions for target PCs? – tiunovs Nov 27 '18 at 04:27
  • The .net framework on the target pc is 4.7.1, so in theory that should work. I found a workaround by changing entry.ExtractToFile() to ZipFile.ExtractToDirectory and that seems to work on the development and target computers – Jeff S. Nov 27 '18 at 16:37

0 Answers0