C# .NET Missing Method Exception when opening ZipArchive created with System.IO.Compression

倖福魔咒の 提交于 2019-12-01 11:08:07

The ZipFile.OpenRead(string) method was added only in .NET 4.5. It does not exist in previous versions.

Your question is not clear about which version of .NET your project targets, nor which version of .NET is installed where you are trying to run it, but undoubtedly, you have targeted .NET 4.5 or higher, but are trying to run the code on which only an older version of .NET is installed.

To fix this, either make sure .NET 4.5 is installed on the machine where you want to run the code, or use the older API. For example, you can write your own OpenRead(string) method without much difficulty:

ZipArchive OpenRead(string filename)
{
    return new ZipArchive(File.OpenRead(filename), ZipArchiveMode.Read);
}
}

This is part of a whole host of binding issues introduced in 4.6x versions of .Net Framework. It may work somewhere, but not other places.

Most of this is related binding redirect issues that they have had between 4.6.1 and 4.7.1. Fixed in 4.7.2. These issues usually manifest themselves when working in the Framework and referencing .Net Standard packages

It is addressed in this framework issue: https://github.com/dotnet/corefx/issues/7702

Your best bet is to use binding redirects in your .Config file, or upgrade to .Net Framework 4.7.2 or later

Here i used Ionic and its working good, You can use

You need to import Ionic.zip to your project.

using (var zip = Ionic.Zip.ZipFile.Read("YourFilePAth")) { enter code here };

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!