<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: System.AccessViolationException when debuging the c# project in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/system-accessviolationexception-when-debuging-the-c-project/m-p/5563397#M40742</link>
    <description>&lt;P&gt;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).&lt;/P&gt;</description>
    <pubDate>Mon, 30 Mar 2015 14:48:15 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2015-03-30T14:48:15Z</dc:date>
    <item>
      <title>System.AccessViolationException when debuging the c# project</title>
      <link>https://forums.autodesk.com/t5/net-forum/system-accessviolationexception-when-debuging-the-c-project/m-p/5562746#M40741</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG title="exceptionDetail.png" alt="exceptionDetail.png" border="0" src="https://forums.autodesk.com/t5/image/serverpage/image-id/160975iE359C5ADEF43EB0B/image-size/original?v=mpbl-1&amp;amp;px=-1" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using AutoCAD 2013 and Visual Studio 2010 C# express.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code of the program:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Data;&lt;BR /&gt;using System.Diagnostics;&lt;BR /&gt;using System.IO;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using System.Web.UI;&lt;BR /&gt;using System.Web.UI.WebControls;&lt;BR /&gt;using LWKDrawing;&lt;BR /&gt;using Autodesk.AutoCAD.DatabaseServices;&lt;BR /&gt;using Ionic.Zip;&lt;BR /&gt;using ConvertPDF;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;namespace LWKpdfProcess&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;class Program&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;static void Main(string[] args)&lt;BR /&gt;{&lt;BR /&gt;new LWKHost();&lt;BR /&gt;String thisprocess = Process.GetCurrentProcess().ProcessName;&lt;BR /&gt;if (Process.GetProcesses().Count(p =&amp;gt; p.ProcessName == thisprocess) &amp;gt; 1)&lt;BR /&gt;return;&lt;BR /&gt;registrationCycle();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;protected static void registrationCycle()&lt;BR /&gt;{&lt;BR /&gt;//Open AutoCAD&lt;BR /&gt;Process[] pname = Process.GetProcessesByName("acad");&lt;BR /&gt;if (pname.Length &amp;gt; 0)&lt;BR /&gt;{&lt;BR /&gt;&lt;STRONG&gt;&lt;U&gt;PDFConversionClass.PublishLayouts(); // Here is the code which pop up the exception&lt;/U&gt;&lt;/STRONG&gt;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;StreamReader textFile = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Program.ini");&lt;BR /&gt;string ProgramPath = textFile.ReadLine();&lt;BR /&gt;textFile.Close();&lt;/P&gt;&lt;P&gt;Process p = new Process();&lt;BR /&gt;p.StartInfo.FileName = ProgramPath;&lt;BR /&gt;p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;&lt;BR /&gt;p.Start();&lt;BR /&gt;p.WaitForExit();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;PDFConversionClass.PublishLayouts(); ,&lt;/U&gt;&lt;/STRONG&gt; this code is calling the method "PublishLayouts()" in the class library&amp;nbsp;ConvertPDF, Here is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.IO;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using Autodesk.AutoCAD.Runtime;&lt;BR /&gt;using Autodesk.AutoCAD.ApplicationServices.Core;&lt;/P&gt;&lt;P&gt;using Autodesk.AutoCAD.DatabaseServices;&lt;BR /&gt;using Autodesk.AutoCAD.PlottingServices;&lt;BR /&gt;using Autodesk.AutoCAD.Publishing;&lt;BR /&gt;using Autodesk.AutoCAD.ApplicationServices;&lt;BR /&gt;using System.Collections.Specialized;&lt;BR /&gt;using System.Diagnostics;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;namespace ConvertPDF&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;public class PDFConversionClass&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// Publishes layouts to a PDF file&lt;BR /&gt;[CommandMethod("PublishLayouts")]&lt;BR /&gt;public static void PublishLayouts()&lt;BR /&gt;{&lt;BR /&gt;short bgPlot = (short)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("BACKGROUNDPLOT");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this class library, I have added reference:&lt;/P&gt;&lt;P&gt;accoremgd.dll&lt;/P&gt;&lt;P&gt;acmgd.dll&lt;/P&gt;&lt;P&gt;acdbmgd.dll&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All are Copy Local : false and point directly insides the folder&amp;nbsp;C:\Program Files\Autodesk\AutoCAD 2013.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone tell me the possible cause of the exception and the solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2015 03:09:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/system-accessviolationexception-when-debuging-the-c-project/m-p/5562746#M40741</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-03-30T03:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: System.AccessViolationException when debuging the c# project</title>
      <link>https://forums.autodesk.com/t5/net-forum/system-accessviolationexception-when-debuging-the-c-project/m-p/5563397#M40742</link>
      <description>&lt;P&gt;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).&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2015 14:48:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/system-accessviolationexception-when-debuging-the-c-project/m-p/5563397#M40742</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2015-03-30T14:48:15Z</dc:date>
    </item>
  </channel>
</rss>

