SevenZipExtractor.SetLibraryPath(...) Problems

Oct 12, 2009 at 9:19 AM

Hi, i'm working with your library and i have this problem, i have an object with this construct:

       public Decompressor()
        {
            this.errors = null;
            
            SevenZipExtractor.SetLibraryPath(SevenZipLibPath);
            
        }

 and i have a problem (i'm working on a web application), the first time, when i create an istance of this object all work fine, but after, the second time i recive this error:

{"Can not load 7-zip library or internal COM error! Message: can not change the library path while the library "<path>"is being used."}

N.B. SevenZipLibPath is pulic static property that contain the complete path of 7z.dll

I solve problem using try {}catch{} but i don't like this "fast and simple solution", i want know if there is another method to solve this problem?

Thank you and excuse my english, i'm italian.

 

Coordinator
Oct 15, 2009 at 9:41 PM

 You are the first who report this problem. SetLibraryPath has always worked for me and hundreds of users. So this is your problem. Really.

Oct 15, 2009 at 10:18 PM

ok, thank you for the answer, now i solve the problem using try catch but i'm confused, i'm not able to understand who generete this error! Patience!

Nov 11, 2009 at 8:25 AM

I also have the same problem in my asp.net web site, and I have no idea what causes it.

Nov 11, 2009 at 9:04 AM

Ok, i'm not alone, i fix the problem using try catch in my application but i thins that this problems can be solved using HttpContext.Current.Application to store started library, until now for me is the same, "i have no idea what causes it", using try catch i tought  the code was very slow but i was wrong. You can use this fix for now?

I always ask for excuse for my bad English (I'm Italian)
Nov 11, 2009 at 9:18 AM

I use try-catch, it works :)

Nov 24, 2009 at 10:43 AM

Try Catch is not the best way to do this since there is some performance overhead when the error is thrown. Can you just set a flag to determine that you already have set the LibraryPath?

Seems there is something else wrong, can you post your code? Maybe I can help.

 

This can be easily fixed in the SevenZipSharp source by modifying this method

public static void SetLibraryPath(string libraryPath)
        {
            if (_ModulePtr != IntPtr.Zero )
            {
                throw new SevenZipLibraryException(
                    "can not change the library path while the library\"" + _LibraryFileName + "\"is being used.");
            }
            if (!File.Exists(libraryPath))
            {
                throw new SevenZipLibraryException(
                    "can not change the library path because the file\"" + libraryPath + "\"does not exist.");
            }
            _LibraryFileName = libraryPath;
        }

to this. Check to see if the library is being set to the previous value, if it is there should be no issues.

public static void SetLibraryPath(string libraryPath)
        {
            if (_ModulePtr != IntPtr.Zero && !libraryPath.Equals(_LibraryFileName,StringComparison.CurrentCultureIgnoreCase) )
            {
                throw new SevenZipLibraryException(
                    "can not change the library path while the library\"" + _LibraryFileName + "\"is being used.");
            }
            if (!File.Exists(libraryPath))
            {
                throw new SevenZipLibraryException(
                    "can not change the library path because the file\"" + libraryPath + "\"does not exist.");
            }
            _LibraryFileName = libraryPath;
        }

 

 

 

Coordinator
Feb 6, 2010 at 6:03 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.