【发布时间】:2012-08-30 02:15:03
【问题描述】:
当我的代码尝试创建 Microsoft.Office.Interop.PowerPoint.Application 的新实例时,有时会出现以下异常:
System.Runtime.InteropServices.COMException (0x80010001): Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80010001 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)).
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
我说有时是因为即使给出相同的输入,它也不会始终如一地发生。此外,它也发生在我也与 PowerPoint 自动化 API 交互的代码的其他部分(同样缺乏一致性)。
我已经尝试了来自 MSDN 本身的 this 解决方案,这似乎是最推荐的解决方案。但是,它似乎没有任何影响,因为我仍然观察到相同的行为。
我的问题是:
- MSDN 解决方案是否适用于 PowerPoint 自动化?
- 如何验证我是否已将其正确应用到我的代码中?
- 有人有替代解决方案吗?
我正在使用 C#、.NET 4 和 PowerPoint 2007。
【问题讨论】:
-
我遇到了同样的问题。也许在这里和那里添加一个 Thread.Sleep(100) 应该有帮助?填充图表需要一些时间来更新图形等,因此在添加更多数据之前您可能需要等待。
标签: c# powerpoint office-interop comexception