title: RegistrationServices.RegisterAssembly error - help!
body: <p>I have an assembly on a shared folder (UNC-path only, no mapped drive).  When I try to register it programmatically via <code>RegistrationServices</code>, I'm getting a strange error.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Reflection;
  using System.Runtime.InteropServices;
  
  namespace BLRegisterAssembly
  {
      public static class BlRegisterAssembly
      {
          public static void Register()
          {
              var asm = Assembly.LoadFile(@"\\myUNCPath\myAssembly.dll");
              var rs = new RegistrationServices();
              rs.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);
              // I've also tried AssemblyRegistrationFlags.None : same error.
          }
      }
  }
  </code></pre>
  
  <p>This is the error I'm getting:</p>
  
  <blockquote>
    <p>"Could not load file or assembly
    '[xxxxxxxxxxxxx],
    Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=[xxxxxxxxxxxxxx]' or
    one of its dependencies. The system
    cannot find the file specified."</p>
  </blockquote>
  
  <p>(The file in question is a referenced assembly that the main assembly uses).  </p>
  
  <p><strong>Some more points:</strong><br/>
  - the referenced assembly is located in the same folder as the main assembly that I'm trying to register.<br/>
  - the folder <strong>cannot</strong> be mapped as a logical drive.  Because of how the network folders are accessed, users in different groups have different drive mappings to the same network folders, and these cannot be modified, per IT policy...<br/></p>
  
  <p>Can anyone point me in the right direction to resolve the problem?</p>
  
  <p><strong>ANSWERED</strong><br/>
  Because I was using <code>Assembly.LoadFile</code>, the dependent assemblies have to be resolved manually via <code>AssemblyResolve</code>. The following code update fixed my woes:</p>
  
  <pre><code>public void Register()
  {
      AppDomain.CurrentDomain.AssemblyResolve += 
        new ResolveEventHandler(CurrentDomain_AssemblyResolve);
  
      var asm = Assembly.LoadFile(Path.Combine(m_path, assemblyName));
      var rs = new RegistrationServices();
      rs.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);
  }
  
  static Assembly CurrentDomain_AssemblyResolve(object sender, 
    ResolveEventArgs args)
  {
      //... code to resolve the path and load the dependent assembly...
  }
  </code></pre>