0

I am kinda new to C# and visual studio. I try to unzip a zip and overwrite files if they already exist with the following function:

using System.IO;
using System.IO.Compression;
ZipFile.ExtractToDirectory(gameZip, rootPath, true);

But it wont accept a bool argument as it should be if i can trust this document: (https://github.com/dotnet/runtime/blob/main/src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFile.Extract.cs#L188)

Looking into the package i am using it seems like it is not supported this way, but i use the same package:

        public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName)
        {
            ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName, null);
        }

        public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName, Encoding entryNameEncoding)
        {
            if (sourceArchiveFileName == null)
            {
                throw new ArgumentNullException("sourceArchiveFileName");
            }

            using ZipArchive source = Open(sourceArchiveFileName, ZipArchiveMode.Read, entryNameEncoding);
            source.ExtractToDirectory(destinationDirectoryName);
        }

So my question is, Why do i have a different version even tho i installed packages from microsoft over the NuGet Package installer: System.IO.Compression.ZipFile and System.IO.Compression (4.3.0) (.NET Framework 4.8)

I tried to find my way through this labyrinth of packages but after 2 days of being stuck at such a simple task just made me post my first question here in Stackoverflow. I hope someone can help me. :D

I tried to extract a zip and set the overwrite boolean to "true" so it overwrite existing files.

  • I'm not sure why you're looking at the internals of the implementation -- look at [the docs](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.extracttodirectory?view=net-7.0#system-io-compression-zipfile-extracttodirectory(system-string-system-string-system-boolean)). – canton7 Jan 27 '23 at 10:03
  • The overload method is in line 75... – shingo Jan 27 '23 at 10:06
  • 2
    I'd encourage you to look at the documentation. Then, having identified the overload you hoped to use, check the "Applies to" section that says what it should work with. [https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.extracttodirectory?view=net-7.0](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.extracttodirectory?view=net-7.0). Notably, *some* of the overloads will work with .NET Framework 4.8, others will not. – Damien_The_Unbeliever Jan 27 '23 at 10:07
  • (Or of course switch the version at the top of the page to the appropriate one and then only applicable overloads should be shown) – Damien_The_Unbeliever Jan 27 '23 at 10:09
  • Oh thank you guys! Not sure why i thought the NET Framework 4.8 is the highest possible version. Guess i just need to upgrade it and then i am good to go. – Minimalistiker Jan 27 '23 at 10:12
  • Use .NET 6 if possible. NET Framework is end-of-life and deprecated and will cause you more pain than good – John Jan 27 '23 at 10:53

0 Answers0