.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

error exitign acad

7 REPLIES 7
Reply
Message 1 of 8
Ed.Jobe
436 Views, 7 Replies

error exitign acad

I have the following sub that works fine...apparently. However, when you close acad, you get an error, usually that the error handler was re-entered. I've traced it to Autodesk.Autocad.Runtime.RxObject.Dispose. When this method is called during shutodown, there is a system.NullObjectReference error. If I comment out this sub, the error does not occur. I can't figure out what there is about this sub that would cause this.
[code]
Public Sub LogPlot()
'Get the csv log file.
Dim LogFile As StreamWriter = File.AppendText(ca.LogFilePath)
'Append plot info
LogFile.WriteLine(ca.Job & "," & ca.Copies & "," & ca.DocName & "," & TimeString() & "," & DateString)
LogFile.Close()
End Sub[/code]

Ed

EESignature

7 REPLIES 7
Message 2 of 8
NathTay
in reply to: Ed.Jobe

What is the ca variable.

Regards - Nathan
Message 3 of 8
Anonymous
in reply to: Ed.Jobe

I have run into similar situation. By "similar", I mean the process involves
object in System.IO namespace, in your case, it is Stream, in my case it is
File object. The symptom is almost identical.

Here is what I had:

In a CAD process, my code does the following:

1. Open several drawings in Acad (4 for now);
2. Have Acad do something with these drawings: inserting a block at given
point;
3. Save the change to each drawing and close it one by one. After all
processed drawings are closed, only an unnamed drawing (Drawing1.dwg) left
open, which is opened when Acad starts;
4. Use System.IO.File.Copy() to move those processed and closed drawings to
a given folder.

All these steps executed just file: drawings are processed correctly (block
inserted), closed normally, and copied to given location. However, when you
close Acad (whether you close the remaining blank drawing first or not), you
got fatal error message after Acad closed and disappeared from screen. The
error, of course, does not affect anything when you start Acad next time,
just a bit annoying.

I found workaround with my code, but the reason of the issue is still
unknown to me, and not solved. My workaround is in step 3 of above, instead
of save the drawing and close it, now I directly save the drawing "As" to
given location (e.g. call Document.CloseAndSave(fileName), if the block
inserting is OK. Thus, I do not need step 4 (e.g. using File.Copy() to move
the closed drawing to given folder). Since no File.IO object is used, when
closing Acad, the error message is gone.

I now recall another .NET API program I wrote a while ago, in which I also
used System.IO.File to rename, copy and delete some files (they are small
*.txt and *.dbf and *.shp, not *.dwg). Since that program deployed, our
Acads often give error message when closing (randomly, not always). Now I
guess it is the same issue.

It must be related with using System.IO namespace with Acad .NET API.

Do someone else also observe this issue?


wrote in message news:5479209@discussion.autodesk.com...
I have the following sub that works fine...apparently. However, when you
close acad, you get an error, usually that the error handler was re-entered.
I've traced it to Autodesk.Autocad.Runtime.RxObject.Dispose. When this
method is called during shutodown, there is a system.NullObjectReference
error. If I comment out this sub, the error does not occur. I can't figure
out what there is about this sub that would cause this.
[code]
Public Sub LogPlot()
'Get the csv log file.
Dim LogFile As StreamWriter = File.AppendText(ca.LogFilePath)
'Append plot info
LogFile.WriteLine(ca.Job & "," & ca.Copies & "," & ca.DocName & ","
& TimeString() & "," & DateString)
LogFile.Close()
End Sub[/code]
Message 4 of 8
Mikko
in reply to: Ed.Jobe

I think you might have to flush the file before you close it.

LogFile.flush()
LogFile.Close()
Message 5 of 8
Ed.Jobe
in reply to: Ed.Jobe

Its a global type that holds the data to be written to file.

Ed

EESignature

Message 6 of 8
Ed.Jobe
in reply to: Ed.Jobe

I'll give that a try. I also tried Dispose on the LogFile and that didn't make any difference. If the problem is like Norman's, in that it is simply related to using System.IO, then I'll use some old vb methods to write to a txt file.

Ed

EESignature

Message 7 of 8
Ed.Jobe
in reply to: Ed.Jobe

It wasn't the previous sub as I thought. It was in another sub that runs after that one during the plot.EndDocument event. The following line was causing the problem:
Dim db As Database = New Database(False, False)

I had to get rid of it and use straight com interop. This is part of the sub mentioned in this thread: http://discussion.autodesk.com/thread.jspa?threadID=539850.

Ed

EESignature

Message 8 of 8
Ed.Jobe
in reply to: Ed.Jobe

Apparently, the cause is because the var pointed to the current doc, when acad disposes of it the var no longer has a valid pointer and thus a Null exception is generated.

Ed

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost