title: Disposing assembly
body: <p>I am trying to show the version numbers of both old and new  to user then copy the new version. When I was trying copy the file after showing the version information I am getting the following exception</p>
  
  <blockquote>
    <p>The process cannot access the file 'C:\Auto TEC\Common.dll' because it is being used by another process.</p>
  </blockquote>
  
  <p>Here is the code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.IO;
  using System.Reflection;
  using System.Diagnostics;
  
  namespace copyfile
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
         private void button1_Click(object sender, EventArgs e)
          {
  
  
              string sourceDirectory = @"E:\newversion\Auto TEC";
              string targetDirectory = @"C:\Auto TEC";
  
              Copy(sourceDirectory, targetDirectory);
              label3.Text = "sucess";
              loadAssembyNames();
  
          }
  
         void f2_FormClosed(object sender, FormClosedEventArgs e)
         {
             this.Close();
         }
         public static void Copy(string sourceDirectory, string targetDirectory)
         {
             DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
             DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);
  
             CopyAll(diSource, diTarget);
  
  
         }
  
         public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
         {
             // Check if the target directory exists, if not, create it.
             if (Directory.Exists(target.FullName) == false)
             {
                 Directory.CreateDirectory(target.FullName);
             }
  
             // Copy each file into it's new directory.
             foreach (FileInfo fi in source.GetFiles())
             {  
  
                 fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
             }
  
             // Copy each subdirectory using recursion.
             foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
             {
                 DirectoryInfo nextTargetSubDir =
                     target.CreateSubdirectory(diSourceSubDir.Name);
                 CopyAll(diSourceSubDir, nextTargetSubDir);
             }
  
         }
          string _errMsg;
          //private AssemblyInformation _info;
          private void getfilenames(string directoryPath, int location)
          {  
              string[] path = new string[25];
              int count = 0;
              foreach (string file in System.IO.Directory.GetFiles(directoryPath))
              {
                  path[count] = file;
                  count++;
  
              }
  
              Assembly asm = null;
  
  
                  for (int i = 0; i &lt; count; i++)
                  {  
                      try
                      {
                         //asm = Assembly.LoadFrom(path[i]);
                          asm = Assembly.LoadFile(path[i]);
                          if (asm != null)
                          {
                              if (location == 1)
                              {
                                  listBox1.Items.Add(asm.GetName().Name + asm.GetName().Version.ToString());
  
                              }
                              else
                              {
                                  listBox2.Items.Add(asm.GetName().Name + asm.GetName().Version.ToString());
                              }
                          }
                      }
                      catch (Exception err)
                      {
                        this._errMsg = err.Message;
                      }
                  }
  
                  asm = null;
  
                  GC.Collect();
  
          }
  
  
  
          private void Form1_Load(object sender, EventArgs e)
          {
              loadAssembyNames();
  
          }
  
          private void loadAssembyNames()
          {
              listBox1.Items.Clear();
              listBox2.Items.Clear();
              getfilenames(@"C:\Auto TEC", 1);
  
              getfilenames(@"E:\newversion\Auto TEC", 2);
          }
      }
  }
  </code></pre>
  
  <p>How do I unload the assembly information from object?</p>