【发布时间】:2020-11-10 23:46:20
【问题描述】:
我有一个使用 Word COM 互操作的 .NET Core 3.1 控制台应用程序,但当它尝试创建 Microsoft.Office.Interop.Word.Application 对象时会引发异常:
System.Runtime.InteropServices.COMException (0x80070520): Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070520 A specified logon session does not exist. It may already have been terminated. (0x80070520).
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type)
这是我正在使用的构造函数调用:
_app = new Application
{
DisplayAlerts = WdAlertLevel.wdAlertsNone,
Visible = false,
FileValidation = MsoFileValidationMode.msoFileValidationSkip,
Caption = "FOO"
};
是什么原因造成的?
【问题讨论】:
-
您在使用 .net 框架应用程序时是否发现任何问题?
-
.NET 4.7.2 存在同样的问题
-
您好,请问您解决了这个问题吗?
-
我最终让它工作了,但是在随机更改了这么多东西之后,我无法告诉你哪一个有效。