簡體   English   中英

C#-“使用”語句似乎未被確認

[英]C#- 'using' statement doesn't appear to be acknowledged

我的應用程序中包含以下代碼塊:

try
{
    string extractPath = @"C:\Documents";
    using (ZipArchive zip = ZipFile.Open(zipFP, ZipArchiveMode.Read))
        foreach(ZipArchiveEntry entry in zip.Entries)
        {
            try
            {
                extractedPDF = System.IO.Path.Combine(extractPath, entry.FullName);
                entry.ExtractToFile(extractedPDF, true);
            }
            catch (System.IO.IOException)
            {
                Console.WriteLine("File already exists... ");
                Console.WriteLine("Error during extraction... ");
            }
        }
    Console.WriteLine("PDF extracted from ZIP: '{0}'...", string.Concat(extractPath, zipFP));
    PdfPanel.OpenFile(extractedPDF);
}catch(AccessViolationException ex)
{
    Console.WriteLine("Can't display a zip in the PDF panel... " + ex.InnerException);
}

目前,我在usingforeach行上遇到編譯錯誤,該行突出顯示了ZipArchiveZipFileZipArchiveModeZipArchiveEntry

編譯錯誤說:

找不到類型或名稱空間名稱“ ZipArchive”(您是否缺少using指令或程序集引用?

但是我在該文件的頂部有一個System.IO.Compressionusing語句,並且我確定我已經添加了代碼所需的所有引用和其他using語句。一個單獨的項目,該項目可以正常運行,並檢查了我是否添加了該項目中所有缺少的using語句和引用。

還有什么可能導致此問題? 為什么編譯器不了解我正在using System.IO.Compression包的事實?

您需要添加對程序集的引用。 在解決方案資源管理器中,在您的項目下,右鍵單擊引用->添加引用。 在“框架程序集”列表中找到System.IO.Compression。 選中復選框,然后按確定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM