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

I’m creating ASP.NET Web Application. I need in it to extract some ‘7z’ files.

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.

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.“. In console app it’s easier because dll files can be placed in Debug folder and it works. Web Application is handled by IIS Express which I guess is the problem.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

It turned out that 7z.dll needs to be in temporary folder created by IIS. It can be accessed using via 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:
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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x