<?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: Fatal Exception when running code in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472708#M55412</link>
    <description>&lt;P&gt;Use LockDocument if you're working with external drawings,&lt;/P&gt;&lt;P&gt;search for "Unhandled Access Violation" on this NG&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 25 May 2012 14:38:46 GMT</pubDate>
    <dc:creator>Hallex</dc:creator>
    <dc:date>2012-05-25T14:38:46Z</dc:date>
    <item>
      <title>Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472610#M55406</link>
      <description>&lt;P&gt;I have been trying to figure this out for a while and I just can't pin point why I get a fatal exception when running this code (see code below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have done this same code (for the mose part) to import pagesetups into the active document and it works fine.&amp;nbsp; however when I run it as it is here to import the page setups into other drawings it seems to always crash autocad.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help!!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;Private Sub copy_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles copy.Click
        Dim psdb As New Database(False, True)
        psdb.ReadDwgFile("M:\CAD Management\CAD Files\Template\Basic.dwt", FileOpenMode.OpenForReadAndReadShare, True, "")
        For Each item In ListBox1.Items
            Dim db As New Database(True, False)
            db.ReadDwgFile(item.ToString, FileOpenMode.OpenForReadAndAllShare, False, "")
            Using trans As Transaction = psdb.TransactionManager.StartTransaction
                Using trns As Transaction = db.TransactionManager.StartTransaction
                    Dim psd As DBDictionary = trans.GetObject(psdb.PlotSettingsDictionaryId, OpenMode.ForRead)
                    Dim id As ObjectId
                    Dim pd As DBDictionary = trns.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForRead)
                    For Each entry As DBDictionaryEntry In pd
                        pd.UpgradeOpen()
                        pd.Remove(entry.Value)
                        pd.DowngradeOpen()
                    Next
                    For Each psent As DBDictionaryEntry In psd
                        id = psd.GetAt(psent.Key)
                        Dim ps As PlotSettings = id.GetObject(OpenMode.ForRead)
                        Dim curps As PlotSettings = New PlotSettings(False)
                        curps.CopyFrom(ps)
                        curps.AddToPlotSettingsDictionary(db)
                        curps.DowngradeOpen()
                    Next
                    trns.Commit()
                    db.SaveAs(item.ToString, DwgVersion.Current)
                    db.CloseInput(True)
                    db.Dispose()
                    trns.Dispose()
                End Using
                trans.Dispose()
            End Using
        Next
        psdb.CloseInput(True)
        psdb.Dispose()
        Me.Close()
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 13:56:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472610#M55406</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-05-25T13:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472616#M55407</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What type of exception are you getting? What line are you getting the exception on?&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 13:58:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472616#M55407</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-05-25T13:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472656#M55408</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;here is the error that I get:&lt;/P&gt;&lt;P&gt;FATAL ERROR: Unhandled Access Violation reading 0xffffffff Exception at db9acc52h&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will either happen after running the code and I start to do something else in autocad or when I close autocad.&lt;/P&gt;&lt;P&gt;I know it has something to so with the code that I am running as it only happens when I run the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also it only seems to happen with the portion of copying the pagesetups, I am not sure what the exact cause is, or which line causes it as it happens after running the code and no other errors appear except the one above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there a way to have it go line by line and run the code and then even after it runs have it give me any errors witht he code?&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 14:18:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472656#M55408</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-05-25T14:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472670#M55409</link>
      <description>&lt;P&gt;This one is beyond me, I only asked cause your code looks similar to my own and I am encountering a similar issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looks like we are both stuck then!&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 14:26:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472670#M55409</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-05-25T14:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472688#M55410</link>
      <description>&lt;P&gt;My theory is that there is something that is hanging out there that I need to stop or close or something that is causeing the error, but I am not sure if that is the case or even how I can tell what it is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I figure out an answer and get this working I will be sure to post it.&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 14:33:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472688#M55410</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-05-25T14:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472700#M55411</link>
      <description>&lt;P&gt;Doesn't Using... negate the need to Dispose() those transactions?&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 14:34:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472700#M55411</guid>
      <dc:creator>dgorsman</dc:creator>
      <dc:date>2012-05-25T14:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472708#M55412</link>
      <description>&lt;P&gt;Use LockDocument if you're working with external drawings,&lt;/P&gt;&lt;P&gt;search for "Unhandled Access Violation" on this NG&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 14:38:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472708#M55412</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-05-25T14:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472770#M55413</link>
      <description>&lt;P&gt;would I lock each external document?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or where would I use the LockDocument?&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 15:04:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472770#M55413</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-05-25T15:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472804#M55414</link>
      <description>&lt;P&gt;Use DocumentLock just for current drawing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;databse db=hostapplicationservices.workingdatabase&lt;/P&gt;&lt;P&gt;document doc=application.documentmanager.mdiactivedocument&lt;/P&gt;&lt;P&gt;using doclock as &amp;nbsp;DocumentLock= doc.LockDocument' current document where you working&lt;/P&gt;&lt;P&gt;using newdb as Database=Readdwg()&lt;/P&gt;&lt;P&gt;using tx as transaction=db.transactionmanager.starttransaction&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'' do you work here&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;end using 'tx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;end using 'newdb&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;end using'' doclock&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 15:26:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472804#M55414</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-05-25T15:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472830#M55415</link>
      <description>&lt;P&gt;ok, I have changed my code on this and I have finally gotten it to work without crashing autocad.&lt;/P&gt;&lt;P&gt;not sure if it is the dispose parts that I have added&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or if it was the exit for parts that I have added, put either way it works without crashing.&lt;/P&gt;&lt;P&gt;hope this helps others&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;code:&lt;/P&gt;&lt;PRE&gt;    Private Sub copy_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles copy.Click
        Using lock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument
            Try
                Dim psdb As New Database(False, True)
                psdb.ReadDwgFile("M:\CAD Management\CAD Files\Template\Basic.dwt", FileOpenMode.OpenForReadAndReadShare, False, "")
                Using trans As Transaction = psdb.TransactionManager.StartTransaction
                    For Each item In ListBox1.Items
                        Dim db As New Database(True, False)
                        db.ReadDwgFile(item.ToString, FileOpenMode.OpenForReadAndAllShare, False, "")
                        Using trns As Transaction = db.TransactionManager.StartTransaction
                            Dim psd As DBDictionary = trans.GetObject(psdb.PlotSettingsDictionaryId, OpenMode.ForRead)
                            Dim id As ObjectId
                            Dim pd As DBDictionary = trns.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForRead)
                            For Each entry As DBDictionaryEntry In pd
                                pd.UpgradeOpen()
                                pd.Remove(entry.Value)
                                pd.DowngradeOpen()
                                Exit For
                            Next
                            For Each psent As DBDictionaryEntry In psd
                                id = psd.GetAt(psent.Key)
                                Dim ps As PlotSettings = id.GetObject(OpenMode.ForRead)
                                Dim curps As PlotSettings = New PlotSettings(False)
                                curps.CopyFrom(ps)
                                curps.AddToPlotSettingsDictionary(db)
                                curps.DowngradeOpen()
                                trns.Commit()
                                curps.Dispose()
                                Exit For
                            Next
                            psd.Dispose()
                            pd.Dispose()
                        End Using
                        db.SaveAs(item.ToString, DwgVersion.Current)
                        db.CloseInput(True)
                        db.Dispose()
                        Exit For
                    Next
                End Using
                psdb.CloseInput(True)
                psdb.Dispose()
            Catch ex As System.Exception
                MsgBox(vbLf &amp;amp; ex.Message)
            End Try
        End Using
        Me.Close()
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 15:46:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3472830#M55415</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-05-25T15:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3473022#M55416</link>
      <description>&lt;P&gt;Good point&lt;/P&gt;&lt;P&gt;Thanks for the sharing with community&lt;/P&gt;&lt;P&gt;Cheers &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2012 17:56:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3473022#M55416</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-05-25T17:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3473478#M55417</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does not the "Exit for" without any condition cause the code to leave the loop inside the first round? Maybe you are not going to reach your problem anymore......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Christian Blei&lt;/P&gt;</description>
      <pubDate>Sat, 26 May 2012 09:40:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3473478#M55417</guid>
      <dc:creator>ChristianBlei</dc:creator>
      <dc:date>2012-05-26T09:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3473576#M55418</link>
      <description>&lt;P&gt;what I found was while this solved the fatal error it stopped copying the pagesetups.&lt;/P&gt;&lt;P&gt;So I did some troubleshooting and realized the the curps.dispose was the issue with it not copying the pagesetup&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however I also discovered that if I removed the exit for and/or the curps.dispose I would get the fatal error again.&lt;/P&gt;&lt;P&gt;so in order for my code to work and copy the pagesetups without giving me the fatal error I had to stop/unload the curps without using curps.dispose and exit for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so a long story somewhat short I did this:&lt;/P&gt;&lt;P&gt;using curps as plotsettings = new plotsettings(false)&lt;/P&gt;&lt;P&gt;(did work)&lt;/P&gt;&lt;P&gt;end using&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This allowed me to copy the pagesetups as I wanted and not get a fatal error in the resulting code I removed all exit for's.&amp;nbsp; What I learned from this is that you have to make sure that everything gets unloaded even the littlest thing still hanging out there can cause an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Sat, 26 May 2012 15:14:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/3473576#M55418</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-05-26T15:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: Fatal Exception when running code</title>
      <link>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/4308177#M55419</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that this thread is over a year old, and am not sure if posting here will still elicit a response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it does not, I will post again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it seems that kenyon is saying that you havet to dispose of the variables as soon as you are done using it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;That means assigning the plot setting to a variable is out of question?&lt;/P&gt;&lt;P&gt;I am trying to write a function that simply returns the plot settings to the mother routine, based on the paper size the user picks in a form.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having no luck in preventing the autocad crash once it cycles through two or three of the page setups.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Intially, it cycled through all layout page setups.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And trying to get it to read any page setup that is not in a layout is out of the question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bauron&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2013 02:44:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/fatal-exception-when-running-code/m-p/4308177#M55419</guid>
      <dc:creator>Bauron</dc:creator>
      <dc:date>2013-06-25T02:44:38Z</dc:date>
    </item>
  </channel>
</rss>

