How can I add a static 'Main' method suitable for an entry point?

How can I add a static 'Main' method suitable for an entry point?

zaheerali43958
Community Visitor Community Visitor
549 Views
2 Replies
Message 1 of 3

How can I add a static 'Main' method suitable for an entry point?

zaheerali43958
Community Visitor
Community Visitor

I am getting an error on my code that say "Error CS5001

Program does not contain a static 'Main' method suitable for an entry point " I am coding in C# using Microsoft Visual Studio and .NET. This is my code. Link

    using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System;






class projectsummer
{
    [CommandMethod("OpenDrawing", CommandFlags.Session)]
   

    public static void OpenDrawing()

    

    {
        string strFileName = "C:\\DRAFT.dwg";
        DocumentCollection acDocMgr = Application.DocumentManager;

        if (File.Exists(strFileName))
        {
            acDocMgr.Open(strFileName, false);
        }
        else
        {
            acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName +
                                                            " does not exist.");
        }
    }
}

I am not sure how to go about this error. Thank you!

0 Likes
550 Views
2 Replies
Replies (2)
Message 2 of 3

AVCPlugins
Advisor
Advisor

You are trying to compile a standalone program, not a plugin library (dll). Set up your project as required by the documentation.
Also, the class must be public. It is desirable to provide the assembly with the CommandClass attribute.
Once again. In order not to ask such questions, you MUST download ObjectARX and practice compiling ready-made examples from the dotNet folder. You can then use these projects as a template. In addition, there is a wizard for VS for creating plugin projects.


Plugins for AutoCAD
A>V>C>
AppStore | Facebook | Twitter | YouTube | Blog
0 Likes
Message 3 of 3

_gile
Consultant
Consultant

Hi,

 

You cannot use the AutoCAD .NET API out of process (i.e., building an .exe).

To be able to use the AutoCAD .NET libraries, you have to build a "class library" project (DLL) and NETLOAD this DLL from a running AutoCAD process.
See this topic about in-process vs out-of-process and you can start from this other one to see how to create an AutoCAD .NET project.

 

You also have to embed your classes into a namespace and a class containig a method which is decored with the CommandMethod attribute have to be public.

 

You should have posted in the .NET forum.

 

I replied a similar question at StackOverflow.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes