
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm having an issue where I receive an AccessViolationException was unhandled error debugging in AutoCAD 2017 using VS 2015 Community Update 3.
The crash occurs when I have my pallet docked with multiple drawing tabs open and I click on the x (to close) a non active drawing.
The crash doesn't identify a specific location in the code but it seems to be after my DocumentActivated event handler here:
Private Sub callback_documentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
If Not Application.DocumentManager.MdiActiveDocument Is Nothing Then
ResetTree()
Else
'now update the tree view
If Not BW_Palette Is Nothing Then
BW_Palette.tvBom.Nodes.Clear()
End If
End If
'MsgBox("Reset Tree")
End Sub
reset tree eventually calls this function in the pallet code:
Private Sub CreateNewTree()
Using locDoc As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument
Dim currdb As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim AppdictId As ObjectId
Dim DivDictId As ObjectId
'Dim rb As ResultBuffer
Dim Stool As cSerializationTool = New cSerializationTool()
Try
'set the object id for the application dictionary member variable
AppdictId = Stool.GetApplicationDictionaryId("BellwetherDesignTech")
'set the object id for the bom dictionary member variable
DivDictId = Stool.GetObjectDictionaryId("BillOfMaterials", AppdictId)
Using trans As Transaction = currdb.TransactionManager.StartTransaction()
Dim DivDict As DBDictionary
DivDict = trans.GetObject(DivDictId, OpenMode.ForRead, False)
Dim DivDictenum As DbDictionaryEnumerator = DivDict.GetEnumerator()
'get each plane xrecord from the structure dictionary
Do While DivDictenum.MoveNext
Dim CatDict As DBDictionary
CatDict = trans.GetObject(DivDictenum.Current.Value, OpenMode.ForRead, False)
Dim nod As Forms.TreeNode = tvBom.Nodes.Add(DivDictenum.Current.Key, DivDictenum.Current.Key)
nod.Tag = "BomCategory"
Dim de As New DictionaryEntry
For Each de In CatDict
Dim pmXrec As Xrecord = trans.GetObject(de.Value, OpenMode.ForRead, False)
Dim childNode As Forms.TreeNode = nod.Nodes.Add(de.Key.ToString, de.Key.ToString)
childNode.Tag = "PieceMark"
Dim BomData As ResultBuffer = pmXrec.Data
Dim TipTxt As String = "Description = " + BomData.AsArray(1).Value.ToString + ControlChars.Lf +
"Material = " + BomData.AsArray(2).Value.ToString + ControlChars.Lf +
"Quantity = " + CStr(BomData.AsArray.Count - 3)
childNode.ToolTipText = TipTxt
Dim reccnt As Integer = 1
For Each tval As TypedValue In BomData
If reccnt > 3 Then
Dim hand As String = tval.Value.ToString
Dim handlenode As Forms.TreeNode = childNode.Nodes.Add(hand, hand)
handlenode.Tag = "PartHandle"
End If
reccnt += 1
Next
Next
Loop
trans.Commit()
End Using
Catch ex As Exception
MsgBox("Problem with Dictionary...(CreateNewTree)")
End Try
End Using
End Sub
It seems that the drawing is trying to close while the CreateNewTree Function still has access to the database. I have tried adding a BeginDocumentClose event handler and find that this is called after the DocumentActivated and by having a message box in here delays the close long enough to stop the program from crashing.
Any direction or help would be greatly appreciated.
Solved! Go to Solution.