RichTextBox Error with AppendText()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I receive an error: "Object reference not set to an instance of an object."
when having this code call which makes no sense as this is a richtextbox
control. I have also placed the trace of this which seems to show this error
occurs within RichTextBox but it doesnt fire the catch. I had to put a
separate startup block in order to even catch this error - otherwise if it
was in the main form it would just fail and disappear with a Windows Forms
error.

Does anyone have a clue what is going on here?

Thanks!
Ben

Private Sub Socks_SessionRemoteDataArrival(ByVal Sender As Object, ByVal
e As ThinkTekLabs.ProxySystem.Base.Session.RemoteDataArrivalEventArgs)
Handles Socks.SessionRemoteDataArrival

Try
Dim s As String = System.Text.Encoding.ASCII.GetString(e.DataB)
RT.AppendText("REMOTE**: " + vbCrLf + s + vbCrLf)
Catch ex As Exception
'MessageBox.Show(ex.Message)

End Try
End Sub

The Try Catch is not triggered and the trace shows the following:

at System.Windows.Forms.RichTextBox.EditStreamProc(IntPtr dwCookie,
IntPtr buf, Int32 cb, Int32& transferred)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.RichTextBox.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg,
HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TestExe.startup.Main()

-----------------------------------------------------------
 
This is caused in the EditStreamProc there can be a write possible to a
Stream which may be set to null by another method. Its possible to fix this
error if they put a check for null on that field at the start of the
EditStreamProc.
 
RichTextBox needs to be called from the same thread it was created on.

Check (RichTextBox.InvokeRequired) - if this is true, call RichTextBox.Invoke or RichTextBox.BeginInvoke on an EventHandler to update the RichTextBox.

I receive an error: "Object reference not set to an instance of an object."
when having this code call which makes no sense as this is a richtextbox
control. I have also placed the trace of this which seems to show this error
occurs within RichTextBox but it doesnt fire the catch. I had to put a
separate startup block in order to even catch this error - otherwise if it
was in the main form it would just fail and disappear with a Windows Forms
error.

Does anyone have a clue what is going on here?

Thanks!
Ben

Private Sub Socks_SessionRemoteDataArrival(ByVal Sender As Object, ByVal
e As ThinkTekLabs.ProxySystem.Base.Session.RemoteDataArrivalEventArgs)
Handles Socks.SessionRemoteDataArrival

Try
Dim s As String = System.Text.Encoding.ASCII.GetString(e.DataB)
RT.AppendText("REMOTE**: " + vbCrLf + s + vbCrLf)
Catch ex As Exception
'MessageBox.Show(ex.Message)

End Try
End Sub

The Try Catch is not triggered and the trace shows the following:

at System.Windows.Forms.RichTextBox.EditStreamProc(IntPtr dwCookie,
IntPtr buf, Int32 cb, Int32& transferred)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.RichTextBox.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg,
HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TestExe.startup.Main()

-----------------------------------------------------------

User submitted from AEWNET (http://www.aewnet.com/)
 
Back
Top