我正在使用以下代码访问 Windows Explorer Shell 的乐队站点服务:
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)
我查看了错误代码,它似乎表明该服务未注册。我很确定实际情况并非如此,因为调用会在几分钟后正常工作,并且 CLSID 由explorer.exe
.
我难住了。什么可能导致 Activator.CreateInstance 失败,但很少发生?