Jump to content

can't reference an assembly that compile suggests I need


Recommended Posts

Posted

Hello,

 

I'm trying to implement a simple C# application in VS 2010 and I'm having difficulty.

 

I'm going through Autodesk's .NET developer's guide and I'm trying out their examples on out-of-process applications (under Basics of the AutoCAD .NET API > Out-Of-Process versus In-Process).

 

Here's the code snippet they offer:

 

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 ");
}

 

Seeing as how this is supposed to work as an out-of-process application, I didn't 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:

 

using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.DatabaseServices;

 

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:

 

[assembly: CommandClass(typeof(OutOfProcess.OutOfProcess))]
namespace OutOfProcess {
public class OutOfProcess
{
   public static void Main()
   {
       OutOfProcess.ConnectToAcad();
   }

 

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 I'm 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:

 

The type or namespace name 'Interop' does not exist in the namespace 'Autodesk.AutoCAD' (are you missing an assembly reference?)

 

This refers to the line using Autodesk.AutoCAD.Interop;

 

Am I missing an assembly reference? I brought in all the .dll's 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

 

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.

 

Since the code does seem to use that ProgID, I'm assuming I do have to reference something related to COM interop (I have no idea what this is, so I'm not sure what I'm 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. I've also searched high and low for what kind of assembly interop requires or where to find it.

 

Any ideas?

 

Thanks

Posted

Those are truly invaluable links, RMS.

 

I was able to find my dll after all. It was under C:\ObjectARX 2011\inc-win32\

 

The problem was that I'm not used to Windows 7 and didn't know how to use the search feature properly. I tried searching using the start menu for Autodesk.AutoCAD.Interop.dll and couldn't find it. But later I tried searching on C:\ from an explorer window and I found what I was looking for.

 

Those links will definitely still come in handy as I will need to learn as much as I can about out-of-process and COM applications.

 

Thanks

Posted

So you got it to run then? Just out of curiosity why would you run out-of-process?

Posted

Just practicing my skills.

 

I got it to run but not without throwing a few exceptions. Working on it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...