One of the most difficult aspects of learning the AutoCAD .NET API, is the
confusion relating to IDisposable.Dispose().
Technically, calling Dispose() on any object that implements IDisposable
should do no harm and have no side-effects, and in most cases that holds
true in the AutoCAD API, with one notable exception, which is the Document
class.
You should *never* call Dispose() on a Document.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010
http://www.acadxtabs.com
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message news:6271399@discussion.autodesk.com...
After running the following command once, any subsequent calls to the
command result in an error. Does anyone no why this would be? The first
time the command runs, the oDocument variable is set without any problems,
but any subsequent command executions error when trying to access the
oDocument variable (e.g., oDatabase = oDocument.Database). The error
states:
{"Object reference not set to an instance of an object."}
{code}
CommandMethod("xTest")> _
Public Sub xTest()
Dim oDocument As Document
Dim oDatabase As Database
Dim oTransaction As Transaction
Dim CommandString As String = ""
Try
oDocument = Application.DocumentManager.MdiActiveDocument
oDatabase = oDocument.Database
MsgBox(oDocument.Name, MsgBoxStyle.OkOnly, "FetzerAW")
'oTransaction =
oDatabase.TransactionManager.StartTransaction
'Using oTransaction
' oTransaction.Commit()
'End Using
Catch ex As System.Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "FetzerAW")
Finally
If oTransaction IsNot Nothing Then oTransaction.Dispose()
If oDatabase IsNot Nothing Then oDatabase.Dispose()
If oDocument IsNot Nothing Then oDocument.Dispose()
End Try
End Sub
{code}