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]