我使用下面的代碼來訪問Windows資源管理器外殼的樂隊現場服務:爲什麼我對Activator.CreateInstance的調用間歇性失敗?
Guid GUID_TrayBandSiteService = new Guid(0xF60AD0A0, 0xE5E1, 0x45cb, 0xB5, 0x1A, 0xE1, 0x5B, 0x9F, 0x8B, 0x29, 0x34);
Type shellTrayBandSiteService = Type.GetTypeFromCLSID(GUID_TrayBandSiteService, true);
site = Activator.CreateInstance(shellTrayBandSiteService) as IBandSite;
大多數情況下,它的偉大工程。的時間(小於1%)一個非常小的比例,調用Activator.CreateInstance拋出以下異常:
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {F60AD0A0-E5E1-45CB-B51A-E15B9F8B2934} failed due to the following error: 80040154.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
我看過了錯誤代碼,它似乎表明服務ISN沒有註冊。我非常確定,實際情況並非如此,因爲通話在稍後會很好地工作,並且CLSID由explorer.exe
提供。
我很難過。什麼可能導致Activator.CreateInstance失敗,但很少?
糾正我,如果我錯了,但不是該對象的存在一個未記錄的實現細節? – 2010-05-23 00:14:36
@Stephen:CLSID在SHOBJIDL.H中定義,但在其他方面沒有記錄。我正在尋找一個實際的答案。如果您對可能導致我觀察到的症狀的想法有所瞭解,那麼我就會全神貫注。即使這是對explorer.exe可能在內部做什麼的猜測。 – 2010-05-23 01:40:11