Here is a code snippet:
readQueue.Refresh();
System.Messaging.Message[] allMessages =
readQueue.GetAllMessages();
foreach (System.Messaging.Message tMessage in allMessages)
{
try
{
//some logic here removed that verifies this is the message
we are waiting for
System.Messaging.Message thisMessage =
readQueue.ReceiveById(tMessage.Id);
response = (string)thisMessage.Body;
OutstandingMessages.Add(response);
}
catch (System.Messaging.MessageQueueException MessE)
{
TraceLogger.WriteLineIf(applicationSwitch.TraceError,
"Message Queue --> Error reading from message queue " + QueueName "
>>> [MessageQueueErrorCode=" + MessE.MessageQueueErrorCode + "]
[ErrorCode=" + MessE.ErrorCode + "]" + MessE.ToString());
if (MessE.InnerException != null)
TraceLogger.WriteLineIf(applicationSwitch.TraceError, "Message Queue --
> Error reading from message queue " + QueueName + " Inner Exception
>>> " + MessE.InnerException.ToString());
}
catch (Exception e)
{
TraceLogger.WriteLineIf(applicationSwitch.TraceError, "Message
Queue --> Error reading from message queue " + listener.QueueName + "
>>> " + e.ToString());
}
}
This code runs through the first time without errors. The expected
message is pulled off and everything works fine. The second time this
code executes, the call the GetAllMessages starts throwing the error
below. NOTE: MessageQueue.EnableConnectionCache is set to false.
Message Queue --> Error reading from message queue
FormatName:DIRECT=OS:RemoteTestMachine\private$\ResponseQueue
[MessageQueueErrorCode=-2147023170] [ErrorCode=-2147467259] >>>
System.Messaging.MessageQueueException
at System.Messaging.MessageEnumerator.get_CursorHandle()
at System.Messaging.MessageEnumerator.MoveNext(TimeSpan timeout)
at System.Messaging.MessageEnumerator.MoveNext()
at System.Messaging.MessageQueue.GetAllMessages()
at StartQueueListener()
There is no actual text associated with the exception, which seems
pretty strange. If anyone can point me in the right direction, it
will be much appreciated.