簡體   English   中英

無法添加對.dll的引用。 請確保文件可訪問,並且它是有效的程序集或COM組件

[英]A reference to .dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component

好的,現在我將盡力解釋我的問題。 我想在我的C#項目中使用流行的壓縮算法7zip

已經有7zip的NuGet軟件包

現在當我安裝7zip頁面https://www.nuget.org/packages/SevenZipSharp/0.64.0時,它安裝得很好,但是當我嘗試運行時卻給出了錯誤

An unhandled exception of type 'SevenZip.SevenZipLibraryException' occurred in SevenZipSharp.dll

Additional information: Can not load 7-zip library or internal COM error! Message: failed to load library

所以我決定手動添加dll文件,並在下面收到此錯誤

    ---------------------------
Microsoft Visual Studio
---------------------------
A reference to 'D:\51_doktora tez projesi\program_crawler\doktora_tez_projesi_crawler_program\ExternalDLLs\7z_9_38_2015_01_03.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
---------------------------
OK   
---------------------------

好的,但是我找到了一個解決方案,並且可以這樣工作

首先安裝nuget包

並在開始調用函數之前設置路徑

SevenZip.SevenZipExtractor.SetLibraryPath("SevenZipSharp.dll");

SevenZip.SevenZipCompressor.SetLibraryPath("SevenZipSharp.dll");

好的第二個問題也很有趣

我想使用最新版本的7zip DLL文件。 因此從官方網站下載了它: https : //sourceforge.net/projects/sevenzip/files/7-Zip/9.38/

已下載MSI,並獲取64bit dll文件。 但是,當我嘗試引用此文件時,它失敗並顯示以上錯誤消息: Please make sure that the file is accessible, and that it is a valid assembly or COM component.

但是把戲再次起作用

我安裝了NuGet 7zip軟件包。 然后在調用函數之前,我設置了這兩行代碼,並且使用了最新版本的DLL文件

SevenZip.SevenZipExtractor.SetLibraryPath("ExternalDLLs/7z_9_38_2015_01_03.dll");
            SevenZip.SevenZipCompressor.SetLibraryPath("ExternalDLLs/7z_9_38_2015_01_03.dll");

所以我正在尋找所有這些事情為什么發生的答案? 為什么我不能直接將DLL文件添加為參考,但是該技巧有效?

Windows 8.1 64位,Visual Studio 2013更新3 WPF應用程序

問題的一部分很可能是因為SevenZipSharp僅僅是7z.dll的包裝,而據我所知,這是一個c ++ dll。 在SevenZipSharp的項目頁面上 ,還提到可以使用任何兼容的dll,並且需要指定它們:

SevenZipSharp需要7-zip本機庫才能運行。 您可以在編譯時,app.config或運行時通過SetLibraryPath()方法在LibraryManager.cs中指定7-zip dll(7z.dll,7za.dll等)的路徑。 +“ 7z.dll”是默認路徑。 對於64位系統,必須使用這些庫的64位版本。 7-zip附帶7z.dll,該文件用於所有存檔操作(通常是“ Program Files \\ 7-Zip \\ 7z.dll”)。 7za.dll是7z.dll的簡易版,它僅支持7zip存檔。 您甚至可以使用7壓縮源中所需的格式來構建自己的庫。 SevenZipSharp將與他們所有人一起工作。

暫無
暫無

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

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