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 (828984)
The information in this article applies to:
- Microsoft Developer Network (MSDN)
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++ .NET (2002)
SYMPTOMSWhen 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 MessageQueue.Send
Method (Object) MessageQueue.Send
Method (Object, MessageQueueTransaction) MessageQueue.Receive
Method MessageQueue.Receive
Method (MessageQueueTransaction) MessageQueue.Receive
Method (TimeSpan, MessageQueueTransaction) CAUSEThe 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 .NETmyQueue.Send("My Message Data.", New _
MessageQueueTransaction()) Microsoft Visual C# .NETmyQueue.Send("My Message Data.", new
MessageQueueTransaction()); Microsoft Visual C++ .NETmyQueue->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" section only if you use
transactional queues. RESOLUTIONTo resolve this problem, start a transaction, and then commit
this transaction after sending a message. To do this, follow these steps:
- In your MyNewQueue class file, locate the following
code:
Visual Basic .NETmyQueue.Send("My Message Data.", New _
MessageQueueTransaction()) Visual C# .NETmyQueue.Send("My Message Data.", new
MessageQueueTransaction()); Visual C++ .NETmyQueue->Send(S"My Message Data.", new MessageQueueTransaction()); - Replace the code that you located in step 1 with the
following code:
Visual Basic .NET' Create a MessageQueueTransaction object.
Dim MyTransaction As New MessageQueueTransaction()
' Start a transaction.
MyTransaction.Begin()
' Send the data as part of a transaction.
myQueue.Send("My Message Data.", MyTransaction)
' Commit the transaction.
MyTransaction.Commit() Visual C# .NET// Create a MessageQueueTransaction object.
MessageQueueTransaction MyTransaction = new MessageQueueTransaction();
// Start a transaction.
MyTransaction.Begin();
// Send the data as part of a transaction.
myQueue.Send("My Message Data.", MyTransaction);
// Commit the transaction.
MyTransaction.Commit(); Visual C++ .NET// Create a MessageQueueTransaction object.
MessageQueueTransaction* MyTransaction = new MessageQueueTransaction();
// Start a transaction.
MyTransaction->Begin();
// Send the data as part of a transaction.
myQueue->Send(S"My Message Data.", MyTransaction);
// Commit the transaction.
MyTransaction->Commit(); - On the Debug menu, click
Start to run your application.
If you use Visual Basic
.NET, you notice the following textual output in the Output window that indicates that your
application has successfully run.
My
Message Data.
If you use Visual C# .NET or if you use
Visual C++ .NET, you notice the previously-mentioned textual output in a
console window that displays this output, and then closes.
STATUS This
behavior is by design.REFERENCESFor more information about the MessageQueue class, visit the following MSDN Web site:
Modification Type: | Major | Last Reviewed: | 10/21/2003 |
---|
Keywords: | kbMsg kbProgramming kbSample kberrmsg kbcode kbprb KB828984 kbAudDeveloper |
---|
|