|
|
I have a problem while using SevenZipSharp. When I use it in a console application, it works fine. But when it is used in a website, the code will raise a SevenZipLibraryException.
Detail
SevenZip.SevenZipLibraryException was caught
Message="Can not load 7-zip library or internal COM error! Message: failed to load library."
Source="SevenZipSharp"
StackTrace:
at SevenZip.SevenZipLibraryManager.LoadLibrary(Object user, Enum format)
at SevenZip.SevenZipExtractor.Init(Stream stream, InArchiveFormat format)
at SevenZip.SevenZipExtractor..ctor(Stream archiveStream, InArchiveFormat format)
Thanks.
|
|
|
Coordinator
Apr 23, 2009 at 11:31 AM
|
Set the library path before any work with Compressor/Extractor, for example SeveZipExtractor.SetLibraryPath(@"path to 7z.dll");
|
|
|
|
|
|
|
|
Coordinator
Apr 23, 2009 at 8:39 PM
|
Try
MessageBox.Show(File.Exists(@"F:\MyTestCode\TestWebSite\Bin\7z.dll") ? "Ok, this is a bug in SevenZipSharp" : "It seems i don't understand something");
before the SevenZipCompressor.SetLibraryPath(@"F:\MyTestCode\TestWebSite\Bin\7z.dll"); line.
|
|
|
|
|
|
|
|
Coordinator
Apr 24, 2009 at 9:38 AM
Edited Apr 24, 2009 at 9:42 AM
|
As for ASP.NET, consider this article:
http://blogs.msdn.com/eldar/archive/2006/09/22/how-to-call-c-dll-from-asp-net-c-code.aspx
This solves your issue.
User gregshutdown uses SevenZipSharp in his ASP.NET site. He asked me to include this code:
LibraryManager.cs, line 44:
private static string LibraryFileName = ConfigurationManager.AppSettings["7zLocation"]?? Path.Combine(Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location), "7z.dll");
I guess he used it somehow.
|
|
|
Coordinator
Jun 4, 2009 at 11:50 AM
|
ginnivanj, for x64 apps, you should use the x64 version of 7z.dll (native 7-zip library) instead of 32 bit.
|
|
|
|
|
Umm... I'm not sure if I stated this before, but I was pretty sure I did O_o
Anyway, for a website to be able to use the 7zip library from a 64 bit .NET app, you have to use the 64 bit 7z.dll. Just download the full 64 bit 7zip app, and take the dll from there :)
Alternatively, compile your app with only x86 support (not "All Platforms") in which case you would be able to use the 32 bit one..
P.S. Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll") in a website will return a path somewhere deep inside the windows dir, not your website's bin directory. That's
why I asked markhor to add the AppSettings part, so that I don't have to specify the dll path EVERY single time I create the extractor or the compressor :P
Best regards,
/me
|
|
|
Dec 30, 2010 at 10:15 PM
Edited Dec 30, 2010 at 11:15 PM
|
hello
Could
you tell
me what
you have
done for not
having
the following bug: Can not load 7-zip library or internal COM error! Message: failed to load library.
for now
I blocked
the above
Here
is an part of my
code in vb.net 2010
:
Imports SevenZip
sub extract(destindl as
string)
If File.Exists(Application.StartupPath &
"\7z.dll") = True
Then
SevenZipExtractor.SetLibraryPath(Application.StartupPath &
"\7z.dll")
Else
Principal.voirinfo("Not Found 7z.dll")
exit sub
End If
Dim ext As SevenZipExtractor =
New SevenZipExtractor(destindl)
'here error
end sub
excuse me for my bad english and thanks you for your help
my
answer
is my
project for x86
and
my version
I used
was of
7z.dll x64
|
|
|
|
|
I think I found the problem after a couple of hours of trying.
If your application/website is running in x64 and you try to SetLibraryPath to the x86, it will fail.
Solution?
1. Make sure you have both 7z.dll and 7z64.dll in your bin folder. I did that by adding the file to the project, using add existing file. Then, on properties, "Copy to outpu directory: always".
2. Now, you need to figure out which version to include:
if (IntPtr.Size == 8) //x64
SevenZip.SevenZipExtractor.SetLibraryPath(Path.Combine(HttpContext.Current.Server.MapPath("~"), "bin", "7z64.dll"));
else //x86
SevenZip.SevenZipExtractor.SetLibraryPath(Path.Combine(HttpContext.Current.Server.MapPath("~"), "bin", "7z.dll"));
|
|
|
|
|
I solve my problem granting access to "network service" user to the 7z.dll file.
sorry for the english.
|
|
|
|
|
tshh wrote:
I have a problem while using SevenZipSharp. When I use it in a console application, it works fine. But when it is used in a website, the code will raise a SevenZipLibraryException.
Detail
SevenZip.SevenZipLibraryException was caught
Message="Can not load 7-zip library or internal COM error! Message: failed to load library."
Source="SevenZipSharp"
StackTrace:
at SevenZip.SevenZipLibraryManager.LoadLibrary(Object user, Enum format)
at SevenZip.SevenZipExtractor.Init(Stream stream, InArchiveFormat format)
at SevenZip.SevenZipExtractor..ctor(Stream archiveStream, InArchiveFormat format)
Thanks.
See my blog post for the solution:
http://blog.jongallant.com/2011/10/7-zip-dll-file-does-not-exist.html
|
|
|
|
|
I don't have any issue in local but in live web server I am also facing same error : Can not load 7-zip library or internal COM error! Message: failed to load library.
we are using the 32 bit server. and here is code
SevenZip.SevenZipExtractor.SetLibraryPath(Path.Combine(HttpContext.Current.Server.MapPath("~"), "bin", "7z.dll"));
please help me to resolve this issue.
Thanks
Mahesh
|
|
|
|
|
How did you do that could you please explain me with step by steps.
Thanks,
Mahesh
|
|
|
|
|
Explain... ¿who?, ¿what of all the things?
|
|
|
|
|
I am getting the dreaded:
Can not load 7-zip library or internal COM error! Message: failed to load library.
This error is starting to drive me crazy. I have been all over the internet and have read every post on this error. I have tried implementing every 'fix' suggested...at least twice. NOTHING gets rid of this error.
I have added SevenZipSharp as a reference and have placed 7z.dll and 7z64.dll in my projects bin directory (also tried loading from Program Files). My code has no problem finding the library(s) at the paths I've provided. The error occurs as soon as I issue a call to CompressStream().
I also made sure my project platform is set to ALL CPUs.
Nothing I do gets rid of this problem. Does ANYONE have any suggestions other than what I've been reading on these sites.
Here is my test code:
try
{
if (IntPtr.Size == 8) //x64
{
SevenZip.SevenZipCompressor.SetLibraryPath(Path.Combine(HttpContext.Current.Server.MapPath("~"), "bin", "7z64.dll"));
}
else //x86
{
SevenZip.SevenZipCompressor.SetLibraryPath(Path.Combine(HttpContext.Current.Server.MapPath("~"), "bin", "7z.dll"));
}
SevenZipCompressor comp = new SevenZipCompressor();
comp.ArchiveFormat = OutArchiveFormat.Tar;
comp.CompressionLevel = CompressionLevel.Normal;
comp.CompressionMode = CompressionMode.Create;
comp.CompressionMethod = CompressionMethod.Copy;
comp.DefaultItemName = fileName;
inStream.Position = 0; // created external to this routine
MemoryStream outStream = new MemoryStream();
//bool canRead = memStreamCompany.CanRead; // verified read/write capabilities on the streams
//bool canWrite = outStream.CanWrite;
comp.CompressStream(inStream, outStream); <--- error occurs here
outStream.Flush();
outStream.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Help anyone?!?
|
|
|
|
|
you gave the user permission to the folder where the library?
with what user do you test the Web application?
|
|
|
|
|
Yes. In the properties/security tab for SevenZipSharp.dll, 7z.dll, and 7z64.dll I have made sure all users have full control rights to these files. I also added a Network Service entry to the security group list and made sure it had full control rights as well. I just verified that all users of these three files have full control rights and tried running my app again. Still can't load the library.
More ideas?
|
|
|
|
|
the folder where you create the compressed file?, has permissions?
|
|
|
|
|
As you can see from the code I posted, I am not trying to compress to disk. I am trying to compress an input stream to an output stream. Both streams are MemoryStreams. But, I've tested both streams for read/write capability and they are fine. The problem is that the SevenZip library cannot be loaded for some reason. That is the crux of my problem I believe. The only error I receive is the old "Can not load 7-zip library or internal COM error! Message: failed to load library."
Since the path to the files themselves seems clear to the SetLibraryPath method, I'm thinking that the problem may have more to do with the second half of the error message..."or internal COM error". There is not enough detail in the error for me to guess at what the COM error issue might be.
|
|
|
|
|
Looking in the debugger at the Compressor object I create (comp in the code above) I notice that the compressor does associate itself with a temp directory on disk. So I checked the permissions on the temp file disk location and found that all entries in the security list had full access to this directory. The files in the directory all appear to be set to read-only, which I tried to clear as a test but the read-only attribute re-asserted itself.
I am still at a loss for the cause of the failure to load the library. I will keep poking around in the debugger and examining the SevenZipSharp objects but I'm hoping someone can save me the time and come up with an answer I haven't seen yet.
Thanks to all who might be noodling on this for me,
|
|
|
|
|
test in stackoverflow.com they respond faster. I have not programmed anything for about 1 year and I do not remember much.
sorry.
|
|
|
|
|
Thanks for the pointer to the other site. I will check it out.
From: nnopazo [email removed]
Sent: Wednesday, February 27, 2013 11:36 AM
To: Robert Alan
Subject: Re: Can not load 7-zip library or internal COM error! Message: failed to load library. [sevenzipsharp:54207]
From: nnopazo
test in stackoverflow.com they respond faster. I have not programmed anything for about 1 year and I do not remember much.
sorry.
Disclaimer: This e-mail and any attachments may contain confidential information belonging to the sender which is legally privileged. This information is intended only for the use of the individual or entity named above. If you are not the intended recipient,
you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this e-mail in error, please immediately notify us by telephone at (617)
600-3240, via our website at www.subpay.com, or by replying to this message.
|
|
|
|
|
One poster above claimed that the problem only exists for web applications. So I have built a WinForms app that does nothing but try to compress an input stream into an output stream. I have done everything suggested in these posts and yet......I am still getting the can't load library error. Here is the code.
Please note that I have added the SevenZipSharp dll as a reference in my project. Intellisense works perfectly so I know my ref is working. Also, the 7z.dll can be found exactly where I'm telling the SetLibraryPath to look for it AND it has full control privileges.
So....what the heck am I missing? Why do other people seem to think this so easy and yet I can't get it to load the library under apparently any circumstance?
try
{
MemoryStream inStream = new MemoryStream();
MemoryStream outStream = new MemoryStream();
StreamWriter sw = new StreamWriter(inStream);
sw.WriteLine(txtInputStream.Text);
sw.Flush();
SevenZipBase.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll");
SevenZipCompressor comp = new SevenZipCompressor();
//comp.ArchiveFormat = OutArchiveFormat.Tar;
//comp.CompressionLevel = CompressionLevel.Normal;
//comp.CompressionMode = CompressionMode.Create;
//comp.CompressionMethod = CompressionMethod.Copy;
comp.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
comp.CompressionLevel = SevenZip.CompressionLevel.Normal;
// comp.DefaultItemName = "pr-123456";
inStream.Position = 0;
//bool canRead = memStreamCompany.CanRead;
//bool canWrite = outStream.CanWrite;
comp.CompressStream(inStream, outStream);
outStream.Flush();
outStream.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
|
|
|
|
|
Try setting the following ... You may specify the custom path to 7-zip dll at SevenZipLibraryManager.LibraryFileName or call SevenZipExtractor.SetLibraryPath(@"c:\Program Files\7-Zip\7z.dll"); or call SevenZipCompressor.SetLibraryPath(@"c:\Program
Files\7-Zip\7z.dll"); > ralan88 > Thursday, 28 February 2013 6:52 AM > > From: ralan88 > > One poster above claimed that the problem only exists for web > applications. So I have built a WinForms app that does nothing but try >
to compress an input stream into an output stream. I have done > everything suggested in these posts and yet......I am still getting > the can't load library error. Here is the code. > > Please note that I have added the SevenZipSharp dll as a
reference in > my project. Intellisense works perfectly so I know my ref is working. > Also, the 7z.dll can be found exactly where I'm telling the > SetLibraryPath to look for it AND it has full control privileges. > > So....what the heck am
I missing? Why do other people seem to think > this so easy and yet I can't get it to load the library under > apparently any circumstance? > |try > { > MemoryStream inStream = new MemoryStream(); > MemoryStream outStream = new MemoryStream();
> StreamWriter sw = new StreamWriter(inStream); > sw.WriteLine(txtInputStream.Text); > sw.Flush(); > > SevenZipBase.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll"); > > SevenZipCompressor comp = new SevenZipCompressor();
> > //comp.ArchiveFormat = OutArchiveFormat.Tar; > //comp.CompressionLevel = CompressionLevel.Normal; > //comp.CompressionMode = CompressionMode.Create; > //comp.CompressionMethod = CompressionMethod.Copy; > > comp.CompressionMethod =
SevenZip.CompressionMethod.Lzma2; > comp.CompressionLevel = SevenZip.CompressionLevel.Normal; > // comp.DefaultItemName = "pr-123456"; > > inStream.Position = 0; > > //bool canRead = memStreamCompany.CanRead; > //bool canWrite
= outStream.CanWrite; > > comp.CompressStream(inStream, outStream); > > outStream.Flush(); > outStream.Close(); > } > catch (Exception ex) > { > Console.WriteLine(ex.Message); > }| > > Read the full discussion online >
. > > To add a post to this discussion, reply to this email > (sevenzipsharp@discussions.codeplex.com > ) > > To start a new discussion for this project, email > sevenzipsharp@discussions.codeplex.com > > > You are receiving this
email because you subscribed to this discussion > on CodePlex. You can unsubscribe or change your settings > > on codePlex.com. > > Please note: Images and attachments will be removed from emails. Any > posts to this discussion will also
be available online at codeplex.com >
Try setting the following ...
You may specify the custom path to 7-zip dll at SevenZipLibraryManager.LibraryFileName
or call SevenZipExtractor.SetLibraryPath(@"c:\Program Files\7-Zip\7z.dll");
or call SevenZipCompressor.SetLibraryPath(@"c:\Program Files\7-Zip\7z.dll");
Thursday, 28 February 2013 6:52 AM
From: ralan88
One poster above claimed that the problem only exists for web applications. So I have built a WinForms app that does nothing but try to compress an input stream into an output stream. I have done everything suggested in
these posts and yet......I am still getting the can't load library error. Here is the code.
Please note that I have added the SevenZipSharp dll as a reference in my project. Intellisense works perfectly so I know my ref is working. Also, the 7z.dll can be found exactly where I'm telling the SetLibraryPath to look for it AND it has full control privileges.
So....what the heck am I missing? Why do other people seem to think this so easy and yet I can't get it to load the library under apparently any circumstance?
try
{
MemoryStream inStream = new MemoryStream();
MemoryStream outStream = new MemoryStream();
StreamWriter sw = new StreamWriter(inStream);
sw.WriteLine(txtInputStream.Text);
sw.Flush();
SevenZipBase.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll");
SevenZipCompressor comp = new SevenZipCompressor();
//comp.ArchiveFormat = OutArchiveFormat.Tar;
//comp.CompressionLevel = CompressionLevel.Normal;
//comp.CompressionMode = CompressionMode.Create;
//comp.CompressionMethod = CompressionMethod.Copy;
comp.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
comp.CompressionLevel = SevenZip.CompressionLevel.Normal;
// comp.DefaultItemName = "pr-123456";
inStream.Position = 0;
//bool canRead = memStreamCompany.CanRead;
//bool canWrite = outStream.CanWrite;
comp.CompressStream(inStream, outStream);
outStream.Flush();
outStream.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
|
|
|
|
|
Does anyone know what the WINCE and MONO flags are about in the SevenZipSharp code?
|
|
|
|
|
Ok, after tracing the SevenZipSharp code within the context of a very simple WinForms app, it became apparent the kernel32 LoadLibrary method was where the failure was occurring. On a whim I re-downloaded the 7z.dll file and guess what...the problem disappeared. So it appears my problem the entire time was a corrupted dll. Glad I found it but I sure wish it didn't take me a day and a half to get to the bottom of it.
So anyone else running in to this. If you've done everything suggested in these posts and it doesn't work...try getting a fresh copy of the dll.
|
|
|
|
|
I encountered exactly the same issue today.
Test code was running great from the Console application, but I got "the load library" error when running the code from my Outlook plugin.
The plugin is a x86 app written in C++ (unmanaged) that uses a mixture of unmanaged and managed code components.
Procmon utility showed that the LoadImage call on 7z.dll was successful. But still I was getting the LoadLibrary error.
I was able to get it to work by re-targeting SevenZip .Net Library from any CPU to x86.
I guess for x64 apps the SevenZip library should be compiled as x64 assembly
Regards,
Michael
|
|