I have a routine to get the counts on a MSMQ queue. I have been using this code for years on 2003 and 2008 server with no trouble. I am now updating the code to run on 2012R2 server and to test this I am compiling with VS2013 premium on Windows 8.1 using the following code:
String sPath;
Int32 nCount = 0;
Object oPath, oNull, oServer;
String [] sParts;
Char [] sSeps = { ':', '\\' };
MSMQ.MSMQQueueManagementClass mgmt;
//
// The configuration path is a standard .net path. For DCOM we need the
// DIRECT= prefixed
//
sPath = "DIRECT=OS:" + m_QueueConfig.QueuePath;
//
// Split the string looking for the sever name
//
sParts = sPath.Split( sSeps, StringSplitOptions.RemoveEmptyEntries );
//
// Get the count from the server
//
mgmt = new MSMQ.MSMQQueueManagementClass();
try
{
oPath = sPath;
oNull = Type.Missing;
if( sParts.Length < 2 || sParts[1] == "." )
oServer = Environment.MachineName;
else
oServer = sParts[1];
mgmt.Init( ref oServer, ref oNull, ref oPath );
nCount = mgmt.MessageCount;
}
catch( Exception )
{
nCount = 0;
}
finally
{
Marshal.ReleaseComObject( mgmt );
}
return nCount;
This will error on the "mgmt. = new MSMQ.MSMQQueueManagementClass()" statement with the following error:
Retrieving the COM class factory for component with CLSID {33B6D07E-F27D-42FA-B2D7-BF82E11E9374} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Looking in the HKEY_CLASSES_ROOT hive I can find 39CE96FE-F4C5-4484-A143-4C2D5D324229 which pointed to the MQOA.DLL in system32, but not the CLSID from the error, which is what a 80040154 is.
I have tried creating a new typelib using the system32/mqoa.dll but I still get the same error. So what I am doing wrong?
According to the registry I have MSMQ version 6.2.9200 installed and it works with my application I just can't get the management interface to load.
mgmt.Init( ref oServer, ref oNull, ref oPath );
The MSMQQueueManagement interface does not have an Init() method. Looks to me like you are mixing up different coclasses. The 39CE96FE guid is for MSMQManagement, the 33B6D07E guid is for MSMQQueueManagment. The latter one is not supposed to appear in the registry so the runtime error is entirely expected. Fix:
mgmt = new MSMQ.MSMQManagement();
// etc..