Test VB app creates 2 Message Queues which receive
messages asynchronously. After a while (variable,
normally about 30 to 40 message received) I get an error
which crashes the app. Below is a the error message, code
(snippet), and the $exception info. Could someone please
tell me what I'm doing wrong.
------<error message>--------
An unhandled exception of type
system.NullReferenceException occurred in
system.Messaging.dll
Additional information: Object reference not set to an
instance of an object
There is no source code available
------<code snippet>--------
Private WithEvents mq1 As New MessageQueue
Private WithEvents mq2 As New MessageQueue
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Initialise mq1
mq1 = New System.Messaging.MessageQueue
("SATURN\Radixxout")
Dim targetTypeNames() As String = _
New String() {"System.String,mscorlib"}
mq1.Formatter = New
System.Messaging.XmlMessageFormatter( _
New String() {"System.String,mscorlib"})
'initialise mq2
mq2 = New System.Messaging.MessageQueue
("SATURN\lms1out")
Dim targetTypeNames2() As String = _
New String() {"System.String,mscorlib"}
mq1.Formatter = New
System.Messaging.XmlMessageFormatter( _
New String() {"System.String,mscorlib"})
mq1.BeginReceive()
mq2.BeginReceive()
End Sub
Private Sub mq1_ReceiveCompleted(ByVal sender As
Object, ByVal e As
System.Messaging.ReceiveCompletedEventArgs) Handles
mq1.ReceiveCompleted
Dim aq As MessageQueue = CType(sender,
MessageQueue)
Dim m As New Message
m = aq.EndReceive(e.AsyncResult)
m.Formatter = New
System.Messaging.XmlMessageFormatter( _
New String() {"System.String,mscorlib"})
Debug.Write("Message received" & vbNewLine)
mq1.BeginReceive()
End Sub
Private Sub mq2_ReceiveCompleted(ByVal sender As
Object, ByVal e As
System.Messaging.ReceiveCompletedEventArgs) Handles
mq2.ReceiveCompleted
Dim aq As MessageQueue = CType(sender,
MessageQueue)
Dim m As New Message
m = aq.EndReceive(e.AsyncResult)
m.Formatter = New
System.Messaging.XmlMessageFormatter( _
New String() {"System.String,mscorlib"})
Debug.Write("Message received" & vbNewLine)
mq2.BeginReceive()
End Sub
------<end code snippet>--------
------<exception info>--------
StackTrace " at
System.Messaging.Interop.MessagePropertyVariants.Unlock()
\r\n at System.Messaging.Message.Unlock()\r\n at
System.Messaging.AsynchronousRequest.RaiseCompletionEvent
(Int32 result, NativeOverlapped* overlappedPointer)\r\n
at System.Messaging.AsynchronousRequest.OnMessageReceived
(Int32 result, IntPtr handle, Int32 timeout, Int32 action,
IntPtr propertiesPointer, NativeOverlapped*
overlappedPointer, IntPtr cursorHandle)" string
- $exception {"Object reference not set to an
instance of an object." }
System.NullReferenceException
- System.SystemException {"Object reference not set
to an instance of an object."} System.SystemException
- System.Exception {"Object reference not set
to an instance of an object." } System.Exception
System.Object {System.NullReferenceException}
System.Object
_className null string
_COMPlusExceptionCode -532459699 int
_exceptionMethod <undefined value>
System.Reflection.MethodBase
_exceptionMethodString null string
_helpURL null string
_HResult -2147467261 int
_innerException { } System.Exception
_message "Object reference not set to an
instance of an object." string
_remoteStackIndex 0 int
_remoteStackTraceString null string
_source null string
+ _stackTrace {System.Array} System.Object
_stackTraceString null string
_xcode -1073741819 int
_xptrs 142734472 int
HelpLink null string
HResult -2147467261 int
InnerException { } System.Exception
Message "Object reference not set to an instance
of an object." string
Source "System.Messaging" string
StackTrace " at
System.Messaging.Interop.MessagePropertyVariants.Unlock()
\r\n at System.Messaging.Message.Unlock()\r\n at
System.Messaging.AsynchronousRequest.RaiseCompletionEvent
(Int32 result, NativeOverlapped* overlappedPointer)\r\n
at System.Messaging.AsynchronousRequest.OnMessageReceived
(Int32 result, IntPtr handle, Int32 timeout, Int32 action,
IntPtr propertiesPointer, NativeOverlapped*
overlappedPointer, IntPtr cursorHandle)" string
+ TargetSite
{System.Reflection.RuntimeMethodInfo}
System.Reflection.MethodBase
+ this
{System.Messaging.Interop.MessagePropertyVariants}
System.Messaging.Interop.MessagePropertyVariants
Here is some psuedo code:
static System.Collections.ArrayList asyncList = new ArrayList(); (This could
be a class level static, instead of a method level static)
AddHandler mq.ReceiveCompleted ....
result = mq.BeginReceive()
asyncList.Add(result);
....
Sub mq_receiveCompleted(..., e as
System.Messaging.ReceiveCompletedEventArgs)...
m = mq.EndReceive(e.AsyncResult)
asyncList.Remove(e.AsyncResult);
...
End Sub
Thanks, Doron
--
This posting is provided "AS IS" with no warranties, and confers no rights.
.
"Robert Croll" <nospamrcr...@optusnet.com.au> wrote in message
news:042b01c349c6$5eb5c970$a501...@phx.gbl...
It solved the most difficult part of the problem. Also
needed to add a timespan object to the mq.BeginReceive()
parameters.
Cheers. I would never have cracked that one without you