13

What is the best way to use MSMQManagement from C#? I need the ability to peek and purge a local outgoing queue when the remote machine is disconnected.

Apparently some users can do this through the COM API, but in the COM References tab, I don't have the "Microsoft Message Queue 3.0 Object Library" that other websites/blogs/postings mention (nor anything remotely similar). I've searched the machine for Interop.MSMQ.dll and cannot find it either.

We are using VS 2008 and running on Windows 7 64-bit.

What am I missing? Are there other mechanisms to accomplish this through "normal" managed classes?

Thanks

3
  • If you do not have MSMQ installed in your Windows 7 machine, go to Control Panel -> Programs and Features and add the Feature MS MQ... Nov 22, 2011 at 22:32
  • MSMQ is installed, as is the DCOM Proxy. I can use "normal" features of MSMQ without problem via the System.Messaging class. What I cannot do is purge or peek messages in a local outgoing queue when the machine on the other end of the queue is disconnected from the network. Either of these operations will throw a MessageQueueException when the machines are not connected.
    – Dan1701
    Nov 23, 2011 at 19:02
  • There are loads of examples on the web of other developers using the COM API to access an MSMQManagement class, via managed code, which is not contained in System.Messaging. These examples demonstrate adding a reference to the "Microsoft Message Queue 3.0 Object Library" via the COM references tab. I do not have this selection. I'm looking for a way to get this DLL, or to at least find out that it won't work on Windows 7/Server 2008.
    – Dan1701
    Nov 23, 2011 at 19:07

2 Answers 2

21

Project + Add Reference, Browse tab. Navigate to c:\windows\system32 (or syswow64 on a 64-bit operating system) and select mqoa30.tlb. This creates the Interop.MSMQ.dll interop assembly you are looking for. Beware that MSMQ is an optional Windows component, you'll need to install it first if the file isn't present on your machine.

4
  • This does not seem to work (at least not in Visual Studio 2010). I get this error: "Could not load file or assembly 'mqoa30.tlb' or one of its dependencies. The module was expected to contain an assembly manifest. This file may not be a managed assembly."
    – Vaccano
    Mar 6, 2012 at 22:58
  • 1
    I've confirmed that this works in Visual Studio 2008 and not in Visual Studio 2010. I asked a question about it here: stackoverflow.com/questions/9593538/…
    – Vaccano
    Mar 6, 2012 at 23:46
  • 1
    Works just fine when I try it in VS2010. You are not using the Browse tab, I don't recognize the screen shot. Mar 7, 2012 at 0:19
  • 3
    I was using Microsoft's "Productivity Power Tools" (visualstudiogallery.msdn.microsoft.com/…). I guess that power tool does not allow Type Libraries. I disabled it and I was able to add the reference just fine.
    – Vaccano
    Mar 7, 2012 at 14:53
3

you can use it natively from .NET by using: System.Messaging.MessageQueue

check these articles:

Accessing Message Queues

Reliable Messaging with MSMQ and .NET

2
  • 1
    System.Messaging is different from the COM API library. System.Messaging does not allow access to the local outgoing queue (unless it's on the same machine as the other end). The MSMQManagement class provides some mechanisms to do this, but I cannot figure out how to access it via managed code.
    – Dan1701
    Nov 22, 2011 at 22:50
  • Just as a note, the C# version is also missing the possibility to send the same message to multiple queues (see MSMQDestination COM object)
    – mBardos
    Feb 10, 2021 at 14:44

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.