COM Interoperability application not running in other computer.

COM Interoperability application not running in other computer.

Anonymous
Not applicable
2,133 Views
5 Replies
Message 1 of 6

COM Interoperability application not running in other computer.

Anonymous
Not applicable

I create a application with VS2015 that using COM Interoperability. It working correctly in my computre but when i copy debug folder and run application , while application wants to drawing object in autocad occure exeption error. i create  a setup file with VS2015 but its not working.

 

this is my cad connection:

 

using System.Runtime.InteropServices;
CadeConnection
    {
        public dynamic Connect()
        {
            string progId = "AutoCAD.Application";
            dynamic acadApp;
            try
            {
                acadApp = Marshal.GetActiveObject(progId);
            }
            catch
            {
                acadApp = Activator.CreateInstance(Type.GetTypeFromProgID(progId));
            }
            while (true)
            {
                try
                {
                    acadApp.Visible = true;
                    break;
                }
                catch { }
            }
            return acadApp;         
        }
}

And i use it like this : 

 

using Autodesk.AutoCAD.Interop.Common;
class DrawInAutocade
    {
        CadeConnection connection = new CadeConnection();
        public void Line(double[] Point1, double[] Point2, string LayerName)
        {
            AcadLine Line = default(AcadLine);
            Line = connection.Connect().ActiveDocument.ModelSpace.AddLine(Point1, Point2);
            Line.Layer = LayerName;   
        }
}

why introp.common and introp files  is not existing  in debug folder of VS2015 ???

0 Likes
Accepted solutions (1)
2,134 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

Hi,

 

This is probably a version compatibility issue.

AutoCAD.Interop libraries may not be version compatible.

 

These libraries aren't copied in the Debug folder because you cannot set the Copy locale proerty to true. AutoCAD find them in the Global Assembly Cache.

 

If you really cannot avoid using the COM API, you can try to remove the references to the interop libraries and use late binding with the dynamic type.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 6

Norman_Yuan
Mentor
Mentor

To _gile,

 

slight correction: AutoCAD installation no longer places its .NET interop assemlies (Autodesk.AutoCAD.Interop.dll and Autodesk.AutoCAD.Interop.Common.dll) into GAC since AutoCAD2013(or 2014?). They are in AutoCAD installation folder.

 

To OP,

 

Firstly as _gile pointed out, you need to make sure it is not version compatibility issue. That is, the other computer has the same version of AutoCAD version (or newer).

 

Also, since you mention that the interop DLLs are not in the "Debug" folder, then it is either expected, or wrong, depending how you add interop references to your project.

 

As aforementioned, if you add references to Autodesk.AutoCAD.Interop/Common.dll in AutoCAD installation folder (or from ObjectARX SDK download folder), you do not include the interop DLLS in your project's output (set "Copy Local" to False), because AutoCAD has these 2 DLLs in its installation folder.

 

However, if you add AutoCAD COM references from "Add References" dialog -> COM tab, and select "AutoCAD 201x type library/Common library", then Visual Studio will use tlbImport.exe to generate corresponding interop DLLs. In this case, you MUST include the interop DLLs in the project's output (Copy Local" set to True).

 

Also, since VS2012, when adding COM interop reference, VS automatically embed COM interop dll as resources in the project. It works OK with MS Offce interop DLLs, but not with AutoCAD's interop DLLs. You need to make sure "Embed Interop Types" is set False.

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 6

Anonymous
Not applicable

I am sure its version compatibility issue. But i am not know how solve it.  I want that my application working correctly with all AutoCAD version.

In my computer i using VS2015 and AutoCAD2018 and i refrenced  Autodesk.AutoCAD.Interop.dll and Autodesk.AutoCAD.Interop.Common.dll from installation folder of AutoCAD 2018. It works well only with AutoCAD2018 in this case. How refrenced Autodesk.AutoCAD.Interop.dll and Autodesk.AutoCAD.Interop.Common.dll that my application working with all version???

0 Likes
Message 5 of 6

Anonymous
Not applicable

How can i use late binding??

0 Likes
Message 6 of 6

_gile
Consultant
Consultant
Accepted solution

seyyed.reza.10 a écrit :

How can i use late binding??


while you do not use variants, it can be quite easy : when you think you code works as expected, remove all reference to the COM libraries and replace the COM types in the code with 'dynamic' type (you may also have to replace the COM enum values with their equivalent integer).

 

class DrawInAutocade
{
    CadeConnection connection = new CadeConnection();
public void Line(double[] Point1, double[] Point2, string LayerName) { dynamic line = connection.Connect().ActiveDocument.ModelSpace.AddLine(Point1, Point2); line.Layer = LayerName; }
}

But, in my opinion, the first question you have to ask yourself is : "Do I absolutely use the COM API, can't I use the .NET API instead?".

 

If you absolutely need to use COM API (i.e. you must build a standalone application), you can also:

- create some custom commands with the .NET API generating a DLL

- get the AutoCAD application from the standalone exe, then load the DLL and the call the commands as shown here.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub