need to reference an assembly that I can't find

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
I hope this is the right forum.
Im trying to implement a simple C# application in VS 2010 and Im having difficulty.
Im going through Autodesks .NET developers guide and Im trying out their examples
on out-of-process applications (under Basics of the AutoCAD .NET API > Out-Of-Process versus In-Process). I donÃt *think* you need to understand much about AutoCAD to understand my problem, so dont be scared off; Its really a question how to reference
(or at least find) an assembly that the compiler suggests I might be missing.
Heres the code snippet they offer:
Code:
<br/>
 
<pre>using System;
using System.Runtime.InteropServices;
 
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
 
[CommandMethod("ConnectToAcad")]
public static void ConnectToAcad()
{
 
  AcadApplication acAppComObj = null;
  const string strProgId = "AutoCAD.Application.18";
 
  // Get a running instance of AutoCAD
  try
  {
      acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId);
  }
  catch // An error occurs if no instance is running
  {
      try
      {
          // Create a new instance of AutoCAD
          acAppComObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);
      }
      catch
      {
          // If an instance of AutoCAD is not created then message and exit
          System.Windows.Forms.MessageBox.Show("Instance of AutoCAD.Application" +
                                              
 " could not be created.");
 
          return;
      }
  }
 
  // Display the application and return the name and version
  acAppComObj.Visible = true;
  System.Windows.Forms.MessageBox.Show("Now running " + acAppComObj.Name + 
                                       " version " + acAppComObj.Version);
 
  // Get the active document
  AcadDocument acDocComObj;
  acDocComObj = acAppComObj.ActiveDocument;
 
  // Optionally, load your assembly and start your command or if your assembly
  // is demandloaded, simply start the command of your in-process assembly.
  acDocComObj.SendCommand("(command " + (char)34 + "NETLOAD" + (char)34 + " " +
                          (char)34 + "c:/myapps/mycommands.dll" + (char)34 + ") ");
 
  acDocComObj.SendCommand("MyCommand ");
}

[/code]
Seeing as how this is supposed to work as an out-of-process application, I didnt create the project as a class library as they say to do in all the previous exercises. Instead I created it as an empty project. I brought in my .cs file as a simple code file
and pasted the above in it - with a few modifications, of course: I included the following references:
Code:
<br/>
using System.Collections.Generic;<br/>
using System.Linq;<br/>
using System.Text;<br/>
using Autodesk.AutoCAD.DatabaseServices;<br/>
I also created a namespace, a class, and a Main method for an entry point as it is going to run as a stand-alone application:
Code:
<br/>
[assembly: CommandClass(typeof(OutOfProcess.OutOfProcess))] 
 namespace OutOfProcess {<br/>
public class OutOfProcess<br/>
{ 
     public static void Main()<br/>
    {<br/>
        OutOfProcess.ConnectToAcad();<br/>
    }<br/>
After this point, the ConnectToAcad() method appears just as in the above code snippet.
I only included these elements in order to get it to work and because all the previous examples had them and Im not experienced enough to know whether or not they can, or should, be left out.
On top of that, I did everything the Autodesk guide told me to do whenever interfacing with AutoCAD APIs - namely: reference acmgd.dll, acdbmgd.dll, accui.dll (as needed - but I referenced them all anyway), and to set their copy local property to false.
Also, to set the target framework to .NET Framework 3.5.
So I did all that, and the build gives me an error that says:
<br/>
The type or namespace name Interop does not exist in the namespace Autodesk.AutoCAD (are you missing an assembly reference?)<br/>
This refers to the line using Autodesk.AutoCAD.Interop;
Am I missing an assembly reference? I brought in all the .dlls it says (i.e. acmgd.dll, acdbmgd.dll, accui.dll) and set their copy local property to false. Is there some other assembly I need?
The guide says
<br/>
As an alternative to executing your .NET application in-process, could use COM interop for your application.
Note The ProgID for COM application access to AutoCAD 2010 is AutoCAD.Application.18.
<br/>
Since the code does seem to use that ProgID, Im assuming I do have to reference something related to COM interop (I have no idea what this is, so Im not sure what Im doing here).
Ive tried variants of the above - for example, setting the framework to 4.0, taking out the namespace stuff, etc. - but none of it works. Ive also searched high and low for what kind of assembly interop requires or where to find it.
Any ideas?
Thanks
<br/>

View the full article
 
Back
Top