Ich habe eine C# .NET (v4.6.2) WinForms App, wo ich auf eine Datei zugreifen kann, die möglicherweise ein .zip-Archiv, das mit "System erstellt wurde .IO.Kompression; ". Ich habe sowohl "System.IO.Compression" und System.IO.Compress.FileSystem "Referenzen im Projekt und" mit System.IO.Compression; "oben, die mit dem NuGet-Paket Installer installiert wurde.System.MissingMethodException beim Versuch, ZipFile aus ZipArchive zu lesen C#
unten ist der Code für den Versuch, die Datei als ZIP-Archiv zu öffnen:
try
{
string extractPath = Path.GetTempFileName();
string strGameVersion = "";
string strProjectType = "";
using (ZipArchive archive = ZipFile.OpenRead(OpenFilePath))
{
FileStream fs = new FileStream(extractPath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.Contains("ProjectData.txt"))
{
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
strGameVersion = sr.ReadLine();
strProjectType = sr.ReadLine();
}
File.Delete(extractPath);
}
sr.Close();
fs.Close();
archive.Dispose();
}
}
catch(System.IO.FileFormatException flex1)
{
MessageBox.Show(flex1.ToString(), "oops.", MessageBoxButtons.OK, MessageBox.Icon.Error);
}
die Fehlermeldung lautet „System.MissingMethodException: Methode nicht gefunden:‚System.IO.Compression.ZipArchive System.IO.Compression. ZipFile.OpenRead (System.String) '. " Also, was mache ich falsch oder gar nicht?
Mögliche Duplikat [C# .NET fehlt Methode Exception beim Öffnen ZipArchive mit System.IO.Compression erstellt] (https: // Stackoverflow. com/questions/44556298/c-sharp-net-missing-method-ausnahme-wenn-öffnung-ziparchive-erstellt-mit-syste) –