gib65 发表于 2022-7-6 22:39:26

can't reference an assemb

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;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:
 

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:
 
 
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
 
 
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

RMS 发表于 2022-7-6 22:55:28

I have not tried this method but I ran into this and thought it might help:
 
http://through-the-interface.typepad.com/through_the_interface/2007/12/launching-autoc.html
 
http://through-the-interface.typepad.com/through_the_interface/2009/05/interfacing-an-external-com-application-with-a-net-module-in-process-to-autocad-redux.html

gib65 发表于 2022-7-6 23:12:51

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

RMS 发表于 2022-7-6 23:39:00

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

gib65 发表于 2022-7-6 23:51:48

Just practicing my skills.
 
I got it to run but not without throwing a few exceptions. Working on it.
页: [1]
查看完整版本: can't reference an assemb