2

Below is an example of the code I am using, but am having trouble finding a fix for the issue. I am VERY green with using C#, but I have referenced the library for 7Zip, although when I compile the code, I get the following error. There is a comment by the line being flagged in Visual Studio.

Error Message: Can not load 7-zip library or internal COM error! Message: library is invalid.

namespace SevenZipTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Compression for Multi-volumes has begun");

            string dll = @"C:\Project\VsProgram\libs\SevenZipSharp.dll";
            string source = @"SourceFilePath";
            string output = @"ZipFileOutputPath";

            SevenZipCompressor.SetLibraryPath(dll);
            SevenZipCompressor compressor = new SevenZipCompressor();
            compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
            compressor.CompressionMode = CompressionMode.Create;
            compressor.TempFolderPath = System.IO.Path.GetTempPath();
            compressor.VolumeSize = 10000000;   // output file size in bytes
            compressor.CompressDirectory(source, output); //This line is where I am getting the flag in the code that gives me the listed error message.

            Console.ReadLine();
        }
    }
}

A few things to note about this is that I have done some research on it, and I have tried different approaches with the code structure too, but most of what I have seen has not provided me with a solution. This is probably a duplicate question, yet I haven't found a source for my purposes.

I've probably read almost every post I can find on this through Google.


With the fix applied in the code, I have been able to run the program, but I now receive an exception saying:

"The execution has failed due to the bug in the SevenZipSharp. Please report about it to http://sevenzipsharp.codeplex.com/WorkItem/List.aspx, post the release number and attach the archive."

I'm looking to see what I can find on this now.

Steven
  • 1,996
  • 3
  • 22
  • 33
spatial_coder
  • 95
  • 1
  • 10

2 Answers2

7

If the startup project is set to "Prefer 32-bit" in its properties, it can result in this error when you specify the 64-bit 7z.dll. Unchecking that property fixed this error for me.

AdvApp
  • 1,094
  • 1
  • 14
  • 27
  • 1
    Thank you for the follow up. I have since moved on from this position, but I did get the solution at the time of the post. More detail is obviously helpful for others who may encounter this. Thanks for the additional information – spatial_coder Apr 23 '20 at 13:13
  • Yes, this one was solving the problem! – Vali Maties Jun 14 '20 at 14:18
  • Yes @ValiMaties I noticed that, I just said the additional piece regarding more detail, for anyone who may need it as a reference later. All information is greatly appreciated as always. – spatial_coder Jun 24 '23 at 01:56
6

SevenZipSharp requires a 7-zip native library to function. You must specify the path to a 7-zip dll (7z.dll, 7za.dll, etc.) in your call to SetLibraryPath.

What you are doing is specifying the path to your SevenZipSharp assembly dll which makes no sense: it is not a native 7zip library. Get 7z.dll (e.g. from here) and set your dll path to it.

Optimax
  • 1,534
  • 2
  • 16
  • 23
  • It was not a comment - it was an answer. On Stack Overflow, if you find someone's answer helpful and it solves your problem, please "accept" it. – Optimax Nov 06 '17 at 17:56
  • I was also trying to edit my previous response, but a the time it wouldn't let me. The program is running now, so I will provide feedback shortly. Thank you for the direction – spatial_coder Nov 06 '17 at 18:20
  • So it runs, but I now have another error. I will post. – spatial_coder Nov 06 '17 at 19:09
  • Thanks. I had found there is a limitation to the Volume Size input. The size was too small and the file quantity for compression would max out at 1000 files and error out. So all I had to do was increase the compression size per file using the Volume Size input and it works. Plus we were testing to see what size would meet our preferences. I appreciate all of the input. Thanks again. – spatial_coder Nov 07 '17 at 14:47