PRB: “System.Messaging.MessageQueueException” Error Message When You Run the MessageQueue.Send Method MSDN Sample Code or When You Run the MessageQueue.Receive Method MSDN Sample Code
Symptoms
When you run the sample code that appears on certain Microsoft Developer Network (MSDN) Web sites, you may receive the following error message:
An unhandled exception of type ‘System.Messaging.MessageQueueException’ occurred in system.messaging.dll
Additional information: External component has thrown an exception.The following MSDN Web sites are affected:
MessageQueue.Send Method
http://msdn2.microsoft.com/en-us/library/system.messaging.messagequeue.send(vs.71).aspx(http://msdn2.microsoft.com/en-us/library/system.messaging.messagequeue.send(vs.71).aspx)
MessageQueue.Send Method (Object)
http://msdn2.microsoft.com/en-us/library/aa329510(VS.71).aspx(http://msdn2.microsoft.com/en-us/library/aa329510(VS.71).aspx)
MessageQueue.Send Method (Object, MessageQueueTransaction)
http://msdn2.microsoft.com/en-us/library/aa329511(VS.71).aspx(http://msdn2.microsoft.com/en-us/library/aa329511(VS.71).aspx)
MessageQueue.Receive Method
http://msdn2.microsoft.com/en-us/library/system.messaging.messagequeue.receive(vs.71).aspx(http://msdn2.microsoft.com/en-us/library/system.messaging.messagequeue.receive(vs.71).aspx)
MessageQueue.Receive Method (MessageQueueTransaction)
http://msdn2.microsoft.com/en-us/library/aa329505(VS.71).aspx(http://msdn2.microsoft.com/en-us/library/aa329505(VS.71).aspx)
MessageQueue.Receive Method (TimeSpan, MessageQueueTransaction)
http://msdn2.microsoft.com/en-us/library/aa329508(VS.71).aspx(http://msdn2.microsoft.com/en-us/library/aa329508(VS.71).aspx)
Resolution
The sample code that appears on these MSDN Web sites contains the following code that may cause you to receive the System.Messaging.MessageQueueException error message.
Microsoft Visual Basic .NET
myQueue.Send(“My Message Data.”, New _MessageQueueTransaction())Microsoft Visual C# .NET
myQueue.Send(“My Message Data.”, newMessageQueueTransaction());Microsoft Visual C++ .NET
myQueue->Send(S”My Message Data.”, new MessageQueueTransaction());You receive the error message because the call to the myQueue.Send method uses a MessageQueueTransaction object without starting a transaction. Additionally, even if you start a transaction before calling the myQueue.Send method, your application may wait indefinitely to receive the sent message. However, your application does not receive a sent message unless the corresponding transaction is committed.
Note The MessageQueue.Send(Object, MessageQueueTransaction) method applies only to transactional queues. Therefore, you receive the error message that is mentioned in the “Symptoms” sectiononly if you use transactional queues.
