title: Autocad & System.Addin, FileNotFoundException for Autocads basic dlls
body: <p>i just started to develop applications for AutoCAD 2016. I want to load my dLLs into a separate AppDomain, so that i don't have to restart ACAD all the time.</p>
  
  <p>After a lot of research and trying i ended up with a pipeline solution 
  using System.Addin and System.Addin.Contract.</p>
  
  <p>I use only interfaces and standardclasses for the Views Contract and Adapters like in this example <a href="https://msdn.microsoft.com/en-us/library/bb788290(v=vs.110).aspx" rel="nofollow">here</a>.</p>
  
  <p>This is my addin containing one methode to write Hello into Acad's Editor and a second methode for drawing a line.</p>
  
  <pre><code>using System.AddIn;
  using CADAddinView;
  using Autodesk.AutoCAD.EditorInput; 
  using Autodesk.AutoCAD.ApplicationServices;
  using Autodesk.AutoCAD.DatabaseServices;
  using Autodesk.AutoCAD.Geometry;
  
  namespace CADAddIn
  {
  [AddIn("cadAddIn", Version = "1.0.0.0")]
  public class CADAddIn : ICADAddinView
  {
      public void drawLine()
      {
          Document acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
          Database acCurDb = acDoc.Database;
  
          using (DocumentLock acLckDoc = acDoc.LockDocument())
          {
              using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
              {
                  DBObject blkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                  BlockTable acBlkTbl = blkTbl as BlockTable;
  
                  BlockTableRecord acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  
                  Polyline acPoly = new Polyline();
                  acPoly.SetDatabaseDefaults();
                  acPoly.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                  acPoly.AddVertexAt(0, new Point2d(100, 100), 0, 0, 0);
  
                  acBlkTblRec.AppendEntity(acPoly);
                  acTrans.AddNewlyCreatedDBObject(acPoly, true);
  
              acTrans.Commit();
              }
          }
      }
  
      public void sayHello()
      {
          Editor ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
          ed.WriteMessage("Hello");
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>this is my HostApplication:</p>
  
  <pre><code>using System.AddIn.Hosting;
  using System.Windows.Forms;
  using CADHostView;
  using System;
  using System.Collections.ObjectModel;
  using Autodesk.AutoCAD.Runtime;
  
  namespace CADHost
  {
  public class CADHost
  {
      [CommandMethod("sayHello")]
      public static void sayHello()
      {
          string addInPath = Environment.CurrentDirectory + "\\Pipeline";
          string[] warnings = AddInStore.Update(addInPath);
          foreach (string warning in warnings)
          {
              MessageBox.Show(warning);
          }
  
          Collection&lt;AddInToken&gt; tokens = AddInStore.FindAddIns(typeof(ICADHostView), addInPath);
  
          if (tokens.Count == 0)
          {
              MessageBox.Show("No AddIn found.");
          }
          else
          {
              AddInToken cadToken = tokens[0];
              ICADHostView cadApp = cadToken.Activate&lt;ICADHostView&gt;(AddInSecurityLevel.Host);
  
              cadApp.sayHello();
          }
      }
  
      [CommandMethod("drawLine")]
      public static void drawLine()
      {
          string addInPath = Environment.CurrentDirectory + "\\Pipeline";
  
          string[] warnings = AddInStore.Update(addInPath);
          foreach (string warning in warnings)
          {
              MessageBox.Show(warning);
          }
  
          Collection&lt;AddInToken&gt; tokens = AddInStore.FindAddIns(typeof(ICADHostView), addInPath);
  
          if (tokens.Count == 0)
          {
              MessageBox.Show("No AddIn found.");
          }
          else
          {
              AddInToken cadToken = tokens[0];
              ICADHostView cadApp = cadToken.Activate&lt;ICADHostView&gt;(AddInSecurityLevel.Host);
  
              cadApp.drawLine();
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Both of the two applications reference to three standard-Dlls from Acad:
  accoremgd.dll, acdbmgd.dll, acmgd.dll. </p>
  
  <p>In both projects these dlls have the option local copy false.
  If i start then i get an Exception, where the programm cannot find the file "accoremgd.dll" and Acad crashes.</p>
  
  <p>So i tried to set the Option local copy true only for the Addin.
  Now it works for the "sayHello"-Methode.</p>
  
  <p>but i get an invalide cast exception when acBlkTbl is initialised.</p>
  
  <p>Would be great if someone has the last steps for me to make this work.
  Also great would be a working example must not be made with the Addinsystem
  i only want to make this work for not restarting acad all the time^^</p>
  
  <p>Thank you for your help
  matthias</p>