SevenZipSharp
SevenZipSharp copied to clipboard
Struggling to get started with SevenZipSharp - Suggestions?
Hi everyone, I am having some issues to start using SevenZipSharp, may I ask you for help? Otherwise, is there any tutorial to get started with SevenZipSharp?
I'd like to create a SFX file, but I am struggling to get started with SevenZipSharp. Here, my code:
var sfx = new SevenZipSfx();
SevenZipCompressor tmp = new SevenZipCompressor();
using (MemoryStream ms = new MemoryStream())
{
tmp.CompressDirectory(@"d:\Temp\", ms);
sfx.MakeSfx(ms, @"d:\Temp\test.exe");
}
When this code is ran, CompressDirectory method throws this exception:
{"Could not load file or assembly 'System.Security.Permissions, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The specified file could not be found.":"System.Security.Permissions, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"}
I did some googling and, as far as I understood, it seems that 7z.dlls are missing. Hence, I tried to add those reference and also use SeveZipSharp.Interop Nuget, but without success. Can anyone point me in the right direction, please? Any help will be really appreciated.
Best regards, Lore
P.S. I also tried to run tests from repository project, but without success. In fact, there is a "testhost.dll" missing error; the solutions provided on stackoverflow were not successful.
First, you'll need to provide a 7z.dll yourself, correct. There are two dll's in the repository (x86 and x64) you could download and use. Either place it in the same directory as the SevenZipSharp dll, or explicitly point it out with LibraryManager.SetLibraryPath.
The missing System.Security.Permissions I'm not sure about, is the project loading correctly, with dependencies and NuGets?
How are you running the tests? I'm using Visual Studio + ReSharper, and the AppVeyor build is using the NUnit console runner.
Ok, thank you!
I tried both ways: place the two dlls of the repository in the same directory as my application (i.e. SeveZipTest) output folder (e.g. ...SevenZipTest\SevenZipTest\bin\Debug\netcoreapp2.1); point the two dlls in code via SetLibraryPath method (e.g. SevenZipCompressor.SetLibraryPath(dllPath); where dllpath = "...SevenZipTest\\SevenZipTest\\bin\\Debug\\netcoreapp2.1\\7z.dll").
Unfortunately, I did not succeed.
SetLibraryPath call throws this exception:
The type initializer for 'SevenZip.SevenZipLibraryManager' threw an exception.
This exception contains an inner exception:
Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
My SevenZipTest application seems to load correctly the nuget: the classes are all resolved, it builds without errors, and runs until exceptions.
The application from repository seems to load the projects correctly with dependencies and nugets, but once tests are ran, two errors are shown in outputs:
[6/19/2019 2:51:18 PM Informational] Executing test method: SevenZip.Tests.MiscellaneousTests.CreateSfxArchiveTest [6/19/2019 2:51:18 PM Informational] ------ Run test started ------ [6/19/2019 2:51:18 PM Error] Unable to find testhost.dll Please publish your test project and retry. [6/19/2019 2:51:18 PM Error] Unable to find testhost.dll Please publish your test project and retry. [6/19/2019 2:51:18 PM Informational] ========== Run test finished: 0 run (0:00:00.3044463) ==========
I simply loaded the solution from visual studio, putted a breaking point in CreateSfxArchiveTest test, and clicked on "debug test(s)". I am using Visual Studio 2019 "vanilla".
P.S. ReSharper and AppVeyor build seem intriguing, I'll take a look at them, thanks!
I could only get it to work if I made a reference to System.Configuration.ConfigurationManager.dll, which also is a referenced nuget package in the SevenZipSharp project.
There are two other additional nuget references in the project:
System.Security.Permissions.dll
System.Security.Cryptography.ProtectedData.dll
It seem to work fine without them but I guess it better to include them to be sure.
(I've attached the files)
Libraries.zip