我试图使用在.NET 4.6.1上运行的ASP.Net应用程序创建一个zip文件夹并向其中添加一个简单的文本文件。我不断抛出错误,我也不知道如何纠正它。该错误是尝试打开Readme.txt文件的结果。我已经在代码中标记了我所看到的错误。我注意到,当尝试打开readmeEntry变量时,它的Length和CompressedLength显示错误“ System.InvalidOperationException”。
System.MissingMethodException:'找不到方法:'Void System.IO.Compression.DeflateStream..ctor(System.IO.Stream, System.IO.Compression.CompressionLevel,布尔值)'。'
using (FileStream zipToOpen = new FileStream(path + "\\" + reportFileNameZip, FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite))
{
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update, true))
{
ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme." + "txt");
using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
{
writer.WriteLine("Information about this package.");
}
} //ERROR MESSAGE //
}