简体   繁体   English

SevenZipSharp 的问题。 7z.dll 库未找到甚至定义的库路径

[英]Problem with SevenZipSharp. 7z.dll library not found even path to lib defined

I'm creating ASP.NET Web Application.我正在创建 ASP.NET Web 应用程序。 I need in it to extract some '7z' files.我需要在其中提取一些“7z”文件。

My code:我的代码:

            SevenZipExtractor.SetLibraryPath(@"<some_path>\7z.dll");

            var zipExtractor = new SevenZipExtractor(zipPath);
            zipExtractor.ExtractArchive(path);

SetLibraryPath, according to SevenZipSharp documentation, should resolve the problem, but it doesn't.根据 SevenZipSharp 文档,SetLibraryPath 应该可以解决问题,但事实并非如此。

During my tests in console app everything works fine but when I'm trying to run my web Application I get " Can not load 7-zip library or internal COM error: Message. failed to load library. ".在我在控制台应用程序中进行测试期间,一切正常,但是当我尝试运行我的 web 应用程序时,我得到“无法加载 7-zip 库或内部 COM 错误:消息。加载库失败。 ”。 In console app it's easier because dll files can be placed in Debug folder and it works.在控制台应用程序中它更容易,因为 dll 文件可以放在 Debug 文件夹中并且它可以工作。 Web Application is handled by IIS Express which I guess is the problem. Web 应用程序由 IIS Express 处理,我猜这是问题所在。

It turned out that 7z.dll needs to be in temporary folder created by IIS.原来 7z.dll 需要在 IIS 创建的临时文件夹中。 It can be accessed using via Assembly:可以通过 Assembly 访问它:

var assemblyDllPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll");

Using that we can copy original 7z.dll to the assembly directory and set SevenZipSharp library path like that:使用它,我们可以将原始 7z.dll 复制到程序集目录并设置 SevenZipSharp 库路径,如下所示:

File.Copy(originalDllPath, assemblyDllPath, overwrite: true);
SevenZipBase.SetLibraryPath(assemblyDllPath);

Note that overwrite is set to true.请注意,覆盖设置为真。 It is because sometimes assembly happens to be the same that one before.这是因为有时组装恰好与以前的组装相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM