一提到.dll文件不能添加。请确认该文件是可访问的,而且它是一个有效的集或COM组件它是、该文件、请确认、组件

2023-09-06 10:31:50 作者:晨曦怒风

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

目前已有的NuGet包7zip的

现在,当我安装7zip的网页。 https://www.nuget.org/packages/ SevenZipSharp / 0.64.0 它安装罚款然而,它提供了错误,当我尝试运行

 键入SevenZip.SevenZipLibraryException的未处理的异常SevenZipSharp.dll发生

其他信息:无法加载7-ZIP库或内部COM错误!消息:无法加载库
 

所以,我决定手动添加dll文件和我得到下面

此错误

  ---------------------------
微软的Visual Studio
---------------------------
一提到D:\ 51_doktora TEZ projesi \ program_crawler \ doktora_tez_projesi_crawler_program \ ExternalDLLs \ 7z_9_38_2015_01_03.dll'不能添加。请确认该文件是可访问的,而且它是一个有效的集或COM组件。
---------------------------
好
---------------------------
 
C 调用C 的dll方法

好了,但我发现了一个解决方案,它的工作原理是这样

首先安装的NuGet包

和开始调用函数设置路径之前

  SevenZip.SevenZipExtractor.SetLibraryPath(SevenZipSharp.dll);

SevenZip.SevenZipCom pressor.SetLibraryPath(SevenZipSharp.dll);
 

确定的第二个问题,这也是有趣的。

我想用7zip的DLL文件的最新版本。因此,从官方网站上下载它: https://sourceforge.net/projects/sevenzip /files/7-Zip/9.38/

下载MSI安装了64位的DLL文件。然而,当我尝试引用该文件时,出现上述错误信息:请确保该文件是可访问的,并且它是一个有效的程序集或COM组件

然而,重施故技作品

我安装的NuGet 7zip的包。然后才调用函数我设置这两条线的code和它使用的DLL文件的最新版本

  SevenZip.SevenZipExtractor.SetLibraryPath(ExternalDLLs / 7z_9_38_2015_01_03.dll);
            SevenZip.SevenZipCom pressor.SetLibraryPath(ExternalDLLs / 7z_9_38_2015_01_03.dll);
 

所以我在寻找答案,为什么这一切会发生?为什么我不能直接添加为基准的DLL文件,但是招的作品?

窗口8.1 64位时,Visual Studio 2013更新3 WPF应用程序

解决方案

你的问题的部分原因最有可能的事实,SevenZipSharp仅仅是一个包装的7z.dll,它尽我所知,是一个C ++的茎DLL 。项目页,对于SevenZipSharp,也提到,任何相容的dll可直接或需要指定

  

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

Ok now i will try to explain my problem as much as possible. I want to use popular compression algorithm 7zip at my c# project

There is already NuGet package for 7zip

Now when i install 7zip page https://www.nuget.org/packages/SevenZipSharp/0.64.0 it installs fine however it gives error when i try to run

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

So i decide to add dll file manually and i get this error below

    ---------------------------
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   
---------------------------

Ok but i found a solution and it works that way

First install nuget package

And before start calling functions set path

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

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

Ok second question which is also interesting

I wanted to use latest version of 7zip DLL file. So downloaded it from official website : https://sourceforge.net/projects/sevenzip/files/7-Zip/9.38/

Downloaded MSI installed and got 64bit dll file. However when i try to reference this file, it fails with error message above: Please make sure that the file is accessible, and that it is a valid assembly or COM component.

However the trick works again

I install NuGet 7zip package. Then before calling functions i set these 2 lines of code and it uses latest version of DLL file

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

So i am looking for answers why all these happens? Why i can not directly add as a reference the DLL file however the trick works?

windows 8.1 64bit, Visual Studio 2013 update 3 WPF application

解决方案

Part of your problem most likely stems from the fact that SevenZipSharp is merely a wrapper for the 7z.dll, which to the best of my knowledge is a c++ dll. The project page, for SevenZipSharp, also mentions that any compatible dll can be used and needs to be specified:

SevenZipSharp requires a 7-zip native library to function. You can specify the path to a 7-zip dll (7z.dll, 7za.dll, etc.) in LibraryManager.cs at compile time, your app.config or via SetLibraryPath() method at runtime. + "7z.dll" is the default path. For 64-bit systems, you must use the 64-bit versions of those libraries. 7-zip ships with 7z.dll, which is used for all archive operations (usually it is "Program Files\7-Zip\7z.dll"). 7za.dll is a light version of 7z.dll, it supports only 7zip archives. You may even build your own library with formats you want from 7-zip sources. SevenZipSharp will work with them all.

 
精彩推荐
图片推荐