System.AccessViolationException when debuging the c# project

System.AccessViolationException when debuging the c# project

Anonymous
Not applicable
1,874 Views
1 Reply
Message 1 of 2

System.AccessViolationException when debuging the c# project

Anonymous
Not applicable

Hi all, 

 

 Recently, I have set up a c# project for plotting the .dwg file to .pdf file. However, when I try to debug the project, it has the following error:

 

exceptionDetail.png

 

 

I am using AutoCAD 2013 and Visual Studio 2010 C# express. 

 

Here is the code of the program: 

using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using LWKDrawing;
using Autodesk.AutoCAD.DatabaseServices;
using Ionic.Zip;
using ConvertPDF;


namespace LWKpdfProcess
{


class Program
{


static void Main(string[] args)
{
new LWKHost();
String thisprocess = Process.GetCurrentProcess().ProcessName;
if (Process.GetProcesses().Count(p => p.ProcessName == thisprocess) > 1)
return;
registrationCycle();
}

 

protected static void registrationCycle()
{
//Open AutoCAD
Process[] pname = Process.GetProcessesByName("acad");
if (pname.Length > 0)
{
PDFConversionClass.PublishLayouts(); // Here is the code which pop up the exception
}
else
{
StreamReader textFile = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Program.ini");
string ProgramPath = textFile.ReadLine();
textFile.Close();

Process p = new Process();
p.StartInfo.FileName = ProgramPath;
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
p.Start();
p.WaitForExit();
}

}

}
}

 

PDFConversionClass.PublishLayouts(); , this code is calling the method "PublishLayouts()" in the class library ConvertPDF, Here is the code:

 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices.Core;

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;
using Autodesk.AutoCAD.Publishing;
using Autodesk.AutoCAD.ApplicationServices;
using System.Collections.Specialized;
using System.Diagnostics;

 

namespace ConvertPDF
{


public class PDFConversionClass
{


// Publishes layouts to a PDF file
[CommandMethod("PublishLayouts")]
public static void PublishLayouts()
{
short bgPlot = (short)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("BACKGROUNDPLOT");
}


}
}

 

For this class library, I have added reference:

accoremgd.dll

acmgd.dll

acdbmgd.dll

 

All are Copy Local : false and point directly insides the folder C:\Program Files\Autodesk\AutoCAD 2013.

 

Could anyone tell me the possible cause of the exception and the solution?

 

0 Likes
Accepted solutions (1)
1,875 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor
Accepted solution

It seems that your app is an stand-alone EXE (a windows console app?). Therefore, your code will not run: the AutoCAD .NET API can only be used within AutoCAD process (i.e. as AutoCAD plugin, NETLOADed into AutoCAD).

Norman Yuan

Drive CAD With Code

EESignature

0 Likes