在c#中创建Excel对象时发生0x8001010A(RPC_E_SERVERCALL_RETRYLATER))异常

问题描述 投票:0回答:1

我正在编写一个用C#编写的excutable,它基本上打开一个现有的Excel文件(在C#中使用Microsoft.Office.Interop.Excel dll)并对其进行一些操作。代码适用于我的用户帐户,但是当我在不同的用户(管理员角色)下运行相同的代码时,它会在_excel = new Application();行引发异常

_excel = new Application(); // throws an exception
_excel.Visible = _showExcel;

以下是例外细节 -

System.Runtime.InteropServices.COMException: Creating an instance of the COM component with CLSID {00024500-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 8001010a The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)).
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)

在任务管理器中,我可以在发生此异常后看到Excel进程。

使用计算机管理>系统工具>本地用户和组>组>管理员,我确认用户处于管理员角色。

我使用powershell命令提示符运行exe文件(以其他用户身份打开)

我已经搜索了很多与此错误相关的页面,但我没有获得与我的具体问题相关的任何成功。

c# .net excel com-interop
1个回答
1
投票

抛出此异常是因为Excel很忙并且不会为任何对象模型调用提供服务。尝试以下代码:

 xlWorkSheet.EnableSelection = xlWorkSheet.EnableSelection = Microsoft.Office.Interop.Excel.XlEnableSelection.xlNoSelection;

如果不行,请关注microsoft solution

© www.soinside.com 2019 - 2024. All rights reserved.