-->

以.dll文件的引用无法添加。 请确保该文件是可访问的,并且它是一个有效的程序集或COM组件(A

2019-10-22 11:37发布

现在好了,我会尝试尽可能地解释我的问题。 我想在我的C#项目使用流行的压缩算法7zip的

已经有NuGet包的7zip的

现在,当我安装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安装了64位的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应用程序

Answer 1:

你的问题的一部分,最有可能的事实,SevenZipSharp仅仅是为7z.dll,这给我所知,是一个C ++ DLL的包装造成的。 该项目页面 ,为SevenZipSharp,也提到了任何兼容的DLL可以使用,需要指定:

SevenZipSharp需要7-ZIP本地库的功能。 您可以在编译时在运行时指定路径中LibraryManager.cs 7-ZIP DLL(7z.dll,了7za.dll等),您的app.config或通过SetLibraryPath()方法。 +“7z.dll”是默认的路径。 对于64位系统,则必须使用这些库的64位版本。 7-ZIP附带7z.dll,这是用于所有归档操作(通常是 “Program Files文件\的7-Zip \ 7z.dll”)。 了7za.dll是7z.dll的简化版,它仅支持7zip的档案。 你甚至可以与您的7-Zip源希望的格式建立自己的图书馆。 SevenZipSharp将与他们所有的工作。



文章来源: 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