我有一個例程來獲取MSMQ隊列上的計數。我一直在2003和2008服務器上使用此代碼多年,沒有任何問題。我現在更新代碼到2012R2服務器上運行,並測試這個我用VS2013編譯溢價在Windows上使用8.1以下代碼:創建類實例時出現MSMQQueueManagement錯誤
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;
的「MGMT這將錯誤=新MSMQ.MSMQQueueManagementClass( )「語句,但出現以下錯誤:
檢索具有CLSID {33B6D07E-F27D-42FA-B2D7-BF82E11E9374}的組件的COM類工廠失敗,原因如下:80040154未註冊的類(從HRESULT異常:0x80040154( REGDB_E_CLASSNOTREG))。
尋找HKEY_CLASSES_ROOT配置單元我可以找到39CE96FE-F4C5-4484-A143-4C2D5D324229,它指向system32中的MQOA.DLL,但不是來自錯誤的CLSID,80040154就是這樣。
我已經嘗試使用system32/mqoa.dll創建一個新的typelib,但我仍然得到相同的錯誤。那麼我做錯了什麼?
根據註冊表,我安裝了MSMQ 6.2.9200版本,它與我的應用程序一起工作,我無法獲取要加載的管理界面。
感謝您的快速回答。這是原始代碼的方式,翻譯中丟失了一些東西。 – 2014-11-03 20:01:00