无法添加对 .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

查看:449
本文介绍了无法添加对 .dll 的引用.请确保该文件可访问,并且它是有效的程序集或 COM 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,现在我会尽量解释我的问题.我想在我的 c# 项目中使用流行的压缩算法 7zip

已经有 7zip 的 NuGet 包

现在当我安装 7zip 页面时 https://www.nuget.org/packages/SevenZipSharp/0.64.0 安装正常,但是当我尝试运行时出现错误

SevenZipSharp.dll 中发生类型为SevenZip.SevenZipLibraryException"的未处理异常附加信息:无法加载 7-zip 库或内部 COM 错误!消息:加载库失败

所以我决定手动添加 dll 文件,我在下面收到此错误

 ---------------------------微软视觉工作室---------------------------无法添加对D:51_doktora tez projesiprogram_crawlerdoktora_tez_projesi_crawler_programExternalDLLs7z_9_38_2015_01_03.dll"的引用.请确保该文件可访问,并且它是有效的程序集或 COM 组件.---------------------------好的---------------------------

好的,但我找到了一个解决方案,它是这样工作的

首先安装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 文件.但是,当我尝试引用此文件时,它失败并显示上述错误消息:请确保该文件可访问,并且它是有效的程序集或 COM 组件.

但是这个技巧又奏效了

我安装了 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 的包装器,据我所知,7z.dll 是一个 c++ dll.项目page,对于SevenZipSharp,也提到可以使用任何兼容的dll,需要指定:><块引用>

SevenZipSharp 需要一个 7-zip 原生库才能运行.您可以在编译时在 LibraryManager.cs 中、您的 app.config 或在运行时通过 SetLibraryPath() 方法指定 7-zip dll(7z.dll、7za.dll 等)的路径.+ "7z.dll" 是默认路径.对于 64 位系统,您必须使用这些库的 64 位版本.7-zip 附带 7z.dll,用于所有存档操作(通常是Program Files7-Zip7z.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 projesiprogram_crawlerdoktora_tez_projesi_crawler_programExternalDLLs7z_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 Files7-Zip7z.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.

这篇关于无法添加对 .dll 的引用.请确保该文件可访问,并且它是有效的程序集或 COM 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆