473,806 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception error occurs on second call to procedure

Hello,

The following code generates an exception error the *second* time it is
called.
Can anyone see what I'm doing wrong?
There is a similar example in Wrox Professional VB.NET Page 289.

Error:
An unhandled exception of type 'System.ObjectD isposedExceptio n'
occurred in mscorlib.dll
Additional information: Cannot write to a closed TextWriter.
The error occurs on this line: Debug.WriteLine ("Date: " & DateTime.Now)
Code:
Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: " & Exception.Messa ge)
objWriter.Flush ()
objWriter.Close ()
objWriter = Nothing

Thank you,
Paul
Nov 21 '05 #1
6 5783
Which line is the error occuring on?

"Paul" <pa**@nospam.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello,

The following code generates an exception error the *second* time it is
called.
Can anyone see what I'm doing wrong?
There is a similar example in Wrox Professional VB.NET Page 289.

Error:
An unhandled exception of type 'System.ObjectD isposedExceptio n'
occurred in mscorlib.dll
Additional information: Cannot write to a closed TextWriter.
The error occurs on this line: Debug.WriteLine ("Date: " & DateTime.Now)
Code:
Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: " & Exception.Messa ge)
objWriter.Flush ()
objWriter.Close ()
objWriter = Nothing

Thank you,
Paul

Nov 21 '05 #2
Try:

Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Dim myTextListener As New TextWriterTrace Listener(objWri ter) '
<<<<----- create a var you can ref
Debug.Listeners .Add(myTextList ener)
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: test")
objWriter.Flush ()
objWriter.Close ()
Debug.Listeners .Remove(myTextL istener) ' <<<<---- remove the ref

HTH,
Greg
"Paul" <pa**@nospam.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello,

The following code generates an exception error the *second* time it is
called.
Can anyone see what I'm doing wrong?
There is a similar example in Wrox Professional VB.NET Page 289.

Error:
An unhandled exception of type 'System.ObjectD isposedExceptio n'
occurred in mscorlib.dll
Additional information: Cannot write to a closed TextWriter.
The error occurs on this line: Debug.WriteLine ("Date: " & DateTime.Now)
Code:
Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: " & Exception.Messa ge)
objWriter.Flush ()
objWriter.Close ()
objWriter = Nothing

Thank you,
Paul

Nov 21 '05 #3
That did it.

Thanks Greg
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
news:uR******** ******@TK2MSFTN GP10.phx.gbl...
Try:

Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Dim myTextListener As New TextWriterTrace Listener(objWri ter) '
<<<<----- create a var you can ref
Debug.Listeners .Add(myTextList ener)
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: test")
objWriter.Flush ()
objWriter.Close ()
Debug.Listeners .Remove(myTextL istener) ' <<<<---- remove the ref

HTH,
Greg
"Paul" <pa**@nospam.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello,

The following code generates an exception error the *second* time it is
called.
Can anyone see what I'm doing wrong?
There is a similar example in Wrox Professional VB.NET Page 289.

Error:
An unhandled exception of type 'System.ObjectD isposedExceptio n'
occurred in mscorlib.dll
Additional information: Cannot write to a closed TextWriter.
The error occurs on this line: Debug.WriteLine ("Date: " & DateTime.Now)
Code:
Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: " & Exception.Messa ge)
objWriter.Flush ()
objWriter.Close ()
objWriter = Nothing

Thank you,
Paul


Nov 21 '05 #4
Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))

So this would create a temporary unamed variable by the framework, which
upon rentering the loop would create it in the same variable name/address
space correct?

At least thats what appears to be happening.

Is this by design?
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
news:uR******** ******@TK2MSFTN GP10.phx.gbl...
Try:

Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Dim myTextListener As New TextWriterTrace Listener(objWri ter) '
<<<<----- create a var you can ref
Debug.Listeners .Add(myTextList ener)
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: test")
objWriter.Flush ()
objWriter.Close ()
Debug.Listeners .Remove(myTextL istener) ' <<<<---- remove the ref

HTH,
Greg
"Paul" <pa**@nospam.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello,

The following code generates an exception error the *second* time it is
called.
Can anyone see what I'm doing wrong?
There is a similar example in Wrox Professional VB.NET Page 289.

Error:
An unhandled exception of type 'System.ObjectD isposedExceptio n'
occurred in mscorlib.dll
Additional information: Cannot write to a closed TextWriter.
The error occurs on this line: Debug.WriteLine ("Date: " & DateTime.Now)
Code:
Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: " & Exception.Messa ge)
objWriter.Flush ()
objWriter.Close ()
objWriter = Nothing

Thank you,
Paul


Nov 21 '05 #5
I dunno.

Even if you assigned it to a variable it would still has a problem when you
run the procedure a second time.

I just took a look at my own code and saw it was having the same problem as
Paul's when ran twice (our code is practically verbatim from the help file
on the subject).

I added a Trace.Listeners .Remove(myTextL istener) and the problem went away.

Not sure why.

So much for looking like a code guru... :^)

Greg
"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))

So this would create a temporary unamed variable by the framework, which
upon rentering the loop would create it in the same variable name/address
space correct?

At least thats what appears to be happening.

Is this by design?
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
news:uR******** ******@TK2MSFTN GP10.phx.gbl...
Try:

Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Dim myTextListener As New TextWriterTrace Listener(objWri ter) '
<<<<----- create a var you can ref
Debug.Listeners .Add(myTextList ener)
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: test")
objWriter.Flush ()
objWriter.Close ()
Debug.Listeners .Remove(myTextL istener) ' <<<<---- remove the ref

HTH,
Greg
"Paul" <pa**@nospam.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> Hello,
>
> The following code generates an exception error the *second* time it is
> called.
> Can anyone see what I'm doing wrong?
> There is a similar example in Wrox Professional VB.NET Page 289.
>
> Error:
> An unhandled exception of type 'System.ObjectD isposedExceptio n'
> occurred in mscorlib.dll
> Additional information: Cannot write to a closed TextWriter.
>
>
> The error occurs on this line: Debug.WriteLine ("Date: " & DateTime.Now)
> Code:
> Dim LogFile As String = "C:\LogFile.txt "
> Dim objWriter As IO.StreamWriter
> objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
> Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))
> Debug.WriteLine ("Date: " & DateTime.Now)
> Debug.Indent()
> Debug.WriteLine ("Error: " & Exception.Messa ge)
> objWriter.Flush ()
> objWriter.Close ()
> objWriter = Nothing
>
> Thank you,
> Paul
>
>



Nov 21 '05 #6
Wasn't trying to do that... was just curious to know how it worked. =)

Thanks though!
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
news:%2******** *********@TK2MS FTNGP11.phx.gbl ...
I dunno.

Even if you assigned it to a variable it would still has a problem when you run the procedure a second time.

I just took a look at my own code and saw it was having the same problem as Paul's when ran twice (our code is practically verbatim from the help file
on the subject).

I added a Trace.Listeners .Remove(myTextL istener) and the problem went away.
Not sure why.

So much for looking like a code guru... :^)

Greg
"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))

So this would create a temporary unamed variable by the framework, which
upon rentering the loop would create it in the same variable name/address space correct?

At least thats what appears to be happening.

Is this by design?
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
news:uR******** ******@TK2MSFTN GP10.phx.gbl...
Try:

Dim LogFile As String = "C:\LogFile.txt "
Dim objWriter As IO.StreamWriter
objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
Dim myTextListener As New TextWriterTrace Listener(objWri ter) '
<<<<----- create a var you can ref
Debug.Listeners .Add(myTextList ener)
Debug.WriteLine ("Date: " & DateTime.Now)
Debug.Indent()
Debug.WriteLine ("Error: test")
objWriter.Flush ()
objWriter.Close ()
Debug.Listeners .Remove(myTextL istener) ' <<<<---- remove the ref
HTH,
Greg
"Paul" <pa**@nospam.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> Hello,
>
> The following code generates an exception error the *second* time it is > called.
> Can anyone see what I'm doing wrong?
> There is a similar example in Wrox Professional VB.NET Page 289.
>
> Error:
> An unhandled exception of type 'System.ObjectD isposedExceptio n'
> occurred in mscorlib.dll
> Additional information: Cannot write to a closed TextWriter.
>
>
> The error occurs on this line: Debug.WriteLine ("Date: " & DateTime.Now) > Code:
> Dim LogFile As String = "C:\LogFile.txt "
> Dim objWriter As IO.StreamWriter
> objWriter = New IO.StreamWriter (LogFile, FileMode.OpenOr Create)
> Debug.Listeners .Add(New TextWriterTrace Listener(objWri ter))
> Debug.WriteLine ("Date: " & DateTime.Now)
> Debug.Indent()
> Debug.WriteLine ("Error: " & Exception.Messa ge)
> objWriter.Flush ()
> objWriter.Close ()
> objWriter = Nothing
>
> Thank you,
> Paul
>
>



Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2912
by: Randy Harris | last post by:
I thought that I had a grasp of how VBA error handling functioned, but have just become painfully aware that I don't. I thought that the "On Error GoTo 0" in the second sub below would turn off error handling for that procedure. I single stepped the program, it gets an error on the last line (the Name Workdir... line), the next command to execute is Resume SkipReport. I know why the error occurs, but I don't understand how it resumes...
44
4236
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
5
2706
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is return ::memcmp(_First1, _First2, _Count); On inspecting these variables, the strings are in fact equal when the exception occurs and _Count is the right size. As a test I replaced this code in the system include file with a for loop to do the...
5
3447
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
4
2257
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
8
1768
by: bole2cant | last post by:
When I add a Button to my NotifyIcon program I get the following: An unhandled exception of type 'System.NullReferenceException' occurred in unknown module. Additional information: Object reference not set to an instance of an object. I suspect this is a common novice error but I haven't any idea what I need to do to get this to work. "Help" seems to be geared toward people who have been coding for a couple of years!
7
1712
by: ZorpiedoMan | last post by:
Well, I'm still wondering around in the "land of the lost exception"... It seems that controls that are bound to a class and the class throws an error in the SET method of the bound member, the exception cannot be caught. I have wrapped my entire application in all the global exception handlers I can find, and still to no avail. In fact all the Try/Catches and Exception event handlers are worthless... Put on your advanced thinking...
1
2493
by: | last post by:
I have an application that has a presentation later, business layer, and data layer. All three projects have their own exception policy, the "UI Policy", "BL Policy", "DL Policy", all of which will log the error in the application event logs. When a database error occurs such as a missing stored procedure, all three policies will log the event resulting in three different entries in the error. My boss says there is a way in the...
9
2953
by: Ratfish | last post by:
I'm getting a "2014:: Commands out of sync; you can't run this command now" error on a php page when I try to call a second stored procedure against a MySQL db. Does anyone know why I might be getting this error? The error doesn't occur on my development box where I use the 'root' db user, but does occur in production where I'm using a non- root user record to establish a connection. I'm essentially opening a connection at the top of...
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10623
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10373
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.