Can't load dll file in coreconsole

Can't load dll file in coreconsole

Miralkong
Advocate Advocate
685 Views
3 Replies
Message 1 of 4

Can't load dll file in coreconsole

Miralkong
Advocate
Advocate

I've trying to use accoreconsole.exe to process a batch of files. According to Kean's blog(https://www.keanw.com/2012/02/the-autocad-2013-core-console.html), coreconsole can also load CRX modules and .NET DLLs that have been coded against the new AcCoreMgd.dll (rather than AcMgd.dll). In my code I only used AcDbMgd.dll and AcCoreMgd.dll as references. However, When I tried to load my dll in coreconsole, it showed that "can't load *** assembly". 

My accoreconsole.exe version is 2021. And my code structure is as below:

        [CommandMethod("TEST", CommandFlags.Session)]
        public void TestCode()
        {
            Document acDoc = AcadCore.Application.DocumentManager.CurrentDocument;
            Database acDb = acDoc.Database;

            using (DocumentLock acLock = acDoc.LockDocument())
            {

                using (Transaction acTrans = acDb.TransactionManager.StartTransaction())
                {
                    // Logic code

                    acTrans.Commit();
                }
            }
            acDb.SaveAs(acDoc.Name, true, DwgVersion.Current, acDb.SecurityParameters);
        }

Could someone tell me why this is happening? Thanks a lot.

0 Likes
Accepted solutions (1)
686 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant

Hi,

 

You should show how you load the DLL.

 

Another thing, is the CommandFlags.Session mandatory for the TestCode method?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 4

Miralkong
Advocate
Advocate

Hi,

I've tried 2 ways to load the dll file. The first one is to open accoreconsole.exe directly and in the command window enter netload. Then when it asks the dll file path, I enter the full path of the released version. The second way is to start a accoreconsole process and then try to load the dll file using StreamWriter.WriteLine() Method. The main structure is as below:

private bool CoreConsleProcess(string programPath, string dwgFilePath, string scriptPath)
        {
            using (Process myProcess = new Process())
            {
                myProcess.StartInfo.UseShellExecute = false;
                //myProcess.StartInfo.CreateNoWindow = true;
                myProcess.StartInfo.FileName = programPath;
                myProcess.StartInfo.RedirectStandardInput = true;
                myProcess.Start();

                StreamWriter myStreamWriter = myProcess.StandardInput;

                myStreamWriter.WriteLine($"open {dwgFilePath}");

                //myStreamWriter.WriteLine($"script {scriptPath}");

                myStreamWriter.WriteLine(@"netload dll full path");

                myStreamWriter.WriteLine("test");

                //myProcess.WaitForExit();

                myProcess.Close();

            }
            return true;
        }

As to the session flag, because I have to save the current database at the end of my code, in my test, if session flag is not assigned, some error is thrown. And I just removed the command session. It can't be loaded neither.

0 Likes
Message 4 of 4

Miralkong
Advocate
Advocate
Accepted solution

Hi Gilles,

This morning I did more test And I found that If I put the dll file in the directory of which the accoreconsole.exe is in, it can be loaded successfully. I don't know if there is a path length limitation in accoreconsole which causes the problem. But it worked in my case. Thanks again.

0 Likes