luuksommers / SevenZipSharp.Interop

Other
36 stars 10 forks source link

Exception occurs when loading library in a standalone WPF application #16

Closed Horiztar closed 3 years ago

Horiztar commented 3 years ago

Everything works fine in the development process when the SevenZipSharp.dll is not packed. But after I packed the whole application into an executable program, this exception occurred. image This is the code.

var libraryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7z.dll");
SevenZip.SevenZipBase.SetLibraryPath(libraryPath);
SevenZip.SevenZipExtractor extractor = new SevenZipExtractor(stream);
quicoli commented 3 years ago

Hi, your Library path isn't correct. You should set the Library path as

// Toggle between the x86 and x64 bit dll var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),Environment.Is64BitProcess ? "x64" : "x86", "7z.dll"); SevenZip.SevenZipBase.SetLibraryPath(path);

Horiztar commented 3 years ago

Thanks for your solution! Actually I have put the dlls in the "BaseDirectory". The problem is probably I compiled x86 executable program but using x64 dll.