title: Could not load file or assembly 'ICSharpCode.SharpZipLib' or one of its dependencies. Access is denied
body: <p>Archiving is working on a remote desktop (coworker) in the office and on the website. I have tested it. </p>
  
  <p>I am writing a service and I need this inside it also. This is not working on my machine, I work remotely and am connected via VPN. The user logged in on this machine belongs to the domain. </p>
  
  <p>Now, before zipping, I am impersonating with a special user account. If I don't do this then this will not even work on the website. </p>
  
  <p>Following is the exception that I am getting. How can i fix it?</p>
  
  <pre><code>System.IO.FileLoadException was caught
    Message=Could not load file or assembly 'ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' or one of its dependencies. Access is denied.
    Source=Project.Helpers
    FileName=ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73
    FusionLog==== Pre-bind state information ===
  LOG: User = Unknown
  LOG: DisplayName = ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73
   (Fully-specified)
  LOG: Appbase = file:///C:/Users/UserPC/Documents/DATA/Projects/ProjectHelperApps/ProjectHelper/TestResults/UserPC_UserPCJ-LAPTOP 2012-08-03 15_50_57/Out
  LOG: Initial PrivatePath = NULL
  Calling assembly : Project.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
  ===
  LOG: This bind starts in default load context.
  LOG: Using application configuration file: C:\Users\UserPC\Documents\DATA\Projects\ProjectHelperApps\ProjectHelper\TestResults\UserPC_UserPCJ-LAPTOP 2012-08-03 15_50_57\Out\Project.Helpers.Tests.DLL.config
  LOG: Using host configuration file: 
  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
  LOG: Post-policy reference: ICSharpCode.SharpZipLib, Version=0.85.3.365, Culture=neutral, PublicKeyToken=1b03e6acf1164f73
  LOG: Attempting download of new URL file:///C:/Users/UserPC/Documents/DATA/Projects/ProjectHelperApps/ProjectHelper/TestResults/UserPC_UserPCJ-LAPTOP 2012-08-03 15_50_57/Out/ICSharpCode.SharpZipLib.DLL.
  ERR: A fatal error occurred when retrieving next codebase for download (hr = 0x80070005).
  
    StackTrace:
         at Project.Helpers.IO.ZipUtility.ZipFiles(String toArchivePath, String destDir, String archiveName, String password, Boolean isDir)
         at Project.Helpers.IO.FileSystem.ArchiveDirectory(String dirToArchive, String destDir, String archiveName)
    InnerException:
  </code></pre>
  
  <p>Here is the archive method:</p>
  
  <pre><code>public bool ArchiveDirectory(string dirToArchive, string destDir, string archiveName)
          {
              bool ok = false;
  
              if (!String.IsNullOrWhiteSpace(dirToArchive) &amp;&amp;
                      !String.IsNullOrWhiteSpace(destDir) &amp;&amp;
                      !String.IsNullOrWhiteSpace(archiveName) &amp;&amp;
                      DirectoryExists(dirToArchive))
              {
                  ok = true;
                  //create destination directory
                  if (!DirectoryExists(destDir))
                      ok = CreateDirectory(destDir);
              }
  
              if (ok)
              {
                  //Archive Name should have .ZIP extension, if not, add it
                  if (!archiveName.ToLowerInvariant().Contains(".zip"))
                      archiveName = archiveName + ".ZIP";
  
                  //Check that the Zip file already exists, if it does then delete it
                  if (FileExists(Path.Combine(destDir, archiveName)))
                      ok = FileDelete(Path.Combine(destDir, archiveName));
              }
  
              if (ok)
              {
                  //Start Impersonation
                  _impersonate.DoImpersonate();
  
                  //Using ZipUtility Class to Zip Directory
                  try
                  {
                      ZipUtility.ZipFiles(dirToArchive, destDir, archiveName, "", true);
                  }
                  catch (SystemException ex)
                  {
                      ok = false;
                  }
                  //end impersonation
                  _impersonate.Dispose();
              }
  
              if (ok)
              {
                  //double check that the archived directory exists
                  ok = FileExists(Path.Combine(destDir, archiveName));
              }
  
              return ok;
          }
  </code></pre>
  
  <p>Please note that impersonation is working as CreateDirectory, FileExists and FileDelete are working without any problem. These 3 methods impersonate first before performing the associated action.</p>
  
  <p>Thanks for looking into it!</p>