检索具有 CLSID {00024500-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败 - 80080005

5

我正在使用Interop打开Excel的一个实例以检索一些数据。不过以下这行代码:

Application xlApp = new Microsoft.Office.Interop.Excel.Application();

出现了此错误:

System.Runtime.InteropServices.COMException
  HResult=0x80080005
  Message=Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
  Source=mscorlib
  StackTrace:
   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, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)

在Office更新到Office Pro Plus之前,这个工作是正常的。在其他机器上,通过将标识更改为DCOM配置中的交互式用户来解决了此问题。

然而,我无法使它工作,尝试了几种其他解决方案(更改权限等),但似乎没有一个能够解决问题。

有人遇到过这个问题并设法解决了吗?


Web应用还是桌面应用? - SᴇM
网络应用程序 - Gertrude
不好意思,很遗憾所有建议的解决方案都没有起作用。 - Gertrude
你尝试过在<system.web>下的Web.config文件中添加<identity impersonate="true" userName="AdminUser" password="Password" />吗? - SᴇM
2个回答

4
问题已解决。看起来我的办公室许可证出现了奇怪的问题。
还需要执行以下步骤:
1. DCOM配置> Office Licensing COM服务器16。右键单击>属性 2. 在标识选项卡中,更新为交互式用户。 3. 在安全选项卡中,在启动和激活权限部分,给正在用作应用程序池身份验证的用户授予本地启动权限。

这段代码可以用于从C#连接到Office 365,但是我必须在web.config中使用模拟设置,如@SeM所述:<identity impersonate="true" userName="AdminUser" password="Password" /> - K Vij

0
解决这个问题的RBAC方法是使用本地的“分布式COM用户”组来授予权限。这比使用“dcomcnfg.exe”更好,因为这是微软提供的现代解决方案。
请确保使用包含应被允许此权限的用户的AD安全组来授予权限,而不是直接将用户添加到本地机器上的组中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接