title: Exception while loading AutoCAD dll dynamically
body: <p>I am working on a project where I have to figure out what version of AutoCAD is installed in the target computer. We have considered the possibility of presence of multiple version of AutoCAD and thus, according to user choice, we have to dynamically load required DLLs from that version of AutoCAD. At first, the program discovers the available versions of AutoCAD and shows it to the User. Then, after selection of a specific version, the program copies DLLs like (accoremgd.dll, acdbmgd.dll, acmgd.dll) to the program directory. But when I try to load those dll dynamically, it shows following error:</p>
  
  <blockquote>
    <p>Could not load file or assembly 'accoremgd.dll' or one of its dependencies. The specified module could not be found.</p>
  </blockquote>
  
  <p>StackTrace:</p>
  
  <blockquote>
    <p>at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark&amp; stackMark)
    at System.Reflection.Assembly.LoadFrom(String assemblyFile)
    at DynamicDLLAdd.Form1.btnLoad_Click(Object sender, EventArgs e) in e:\AutoCadOperations\Test.AutoCadLoad_Re\DynamicDLLAdd\Form1.cs:line 140</p>
  </blockquote>
  
  <p>My sub-routine which dynamically loads the file is:</p>
  
  <pre><code>try
  {
      string destFile = @Path.Combine(Environment.CurrentDirectory,"accoremgd.dll"); 
      if (!File.Exists(destFile))
          return;
  
      Assembly a = null;
      a = Assembly.LoadFrom(destFile);
  
      AppDomain.CurrentDomain.Load(a.GetName());
      MessageBox.Show("LOADED");
      Type classType = a.GetType("Autodesk.AutoCAD.ApplicationService.Document");
      object obj = Activator.CreateInstance(classType);
      MethodInfo mi = classType.GetMethod("Create");
      //rest of the code here
  }
  catch (Exception exp)
  {
      MessageBox.Show(exp.Message);
      MessageBox.Show(exp.Source);
      MessageBox.Show(exp.StackTrace);
  }
  </code></pre>
  
  <p>I think the problem might with the dll's dependencies. What should be done? Is there any documents or articles available? </p>
  
  <p><b>Update:</b>
  The program's Target Framework is 4.0 and Platform target is Any CPU.</p>
  
  <p>I ran fuselogvw.exe and I think here might be some clue to my problem. I have no idea what is going on here so, I have added a picture. It would be a great help if clarifies it.
  <a href="https://i.stack.imgur.com/7S7uD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7S7uD.png" alt="enter image description here"></a></p>