.NET Framework Bookmark and Share   
 index > .NET Base Class Library > No exception occured while sending message into deleted queue
 

No exception occured while sending message into deleted queue

The following sample applicationworks on .Net Framework 2.0 anddoesn't raise any exception.

Is it a bug? Is there any workaround?

using System;



namespace MQDeleteTest

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                // Local public queue.

                string queuePath = ".\\TestQueue";



                System.Messaging.MessageQueue.Create(queuePath);



                System.Messaging.MessageQueue queue =

                    new System.Messaging.MessageQueue(queuePath, false, false);



                queue.Send("A test message 1.");



                System.Messaging.MessageQueue.Delete(queuePath);



                // an exception expected!!!

                queue.Send("A test message 2.");

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex);

            }

        }

    }

}



Antokha
failed messages go to the dead letter queue, no exception is generated. Read more here: http://msdn.microsoft.com/en-us/library/ms789035.aspx
Vapor
Unfortunately, in this sample a message sent to a local queue doesn't go to the dead letter queue.

If the line "queue.Send("A test message 1.");" is commented than the sending of the message 2 will cause an exception.
Antokha

queue.Send("A test message 1.") will trigger resource allocation operations on the queue, close the queue before delete and you will get the expected exception:

// Local public queue.
string queuePath = ".\\TestQueue";
System.Messaging.MessageQueue.Create(queuePath);
System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(queuePath, false, false);

queue.Send("A test message 1.");
queue.Close();
System.Messaging.MessageQueue.Delete(queuePath);

// an exception expected!!!
queue.Send("A test message 2.");

Thanks,
Eric


Please remember to mark helpful replies as answers and unmark them if they provide no help.
eryang

In the sample I don't need to close the queue before sending the second message.

And I also don't need to delete the queue - imagine that it is deleted by someone else, e.g. anexternal process.

I expect an exception fired when I'm sending a message through a queue which doesn't existbut it is not raised!

I just loose a message without any notification!

Antokha

You can use google to search for other answers

Custom Search

More Threads

• Drag and drop of a PictureBox in
• Directory.CreateDirectory method is not running on remote web server.
• Detect USB Version Available
• WMI from C# Error
• fprintf equivalent in .NET
• about project
• change image size to be passed amoung applications
• FORTRAN
• RSA Class, RSAParameters
• Downloading the documentation