首页 > 解决方案 > 调用 GetActiveInstance 时出现 NetofficeFw 异常

问题描述

我正在尝试在以 64 位运行的 Visual Studio 2017 应用程序上使用 NetOfficeFw 1.7.8 打开 Outlook 365(32 位)的活动实例。我打开了 Outlook 365。我的课是这样开始的:

using System;
using System.Linq;
using NetOffice.OutlookApi;
using NetOffice.OutlookApi.Enums;
using Prism.Core;
using Prism.Core.SimpleTypes;

namespace Prism.MSOffice.Integration
{
    public class OutlookActivity : Entity
    {
        public string Subject { get; set; }
        public string Body { get; set; }
        public string Location { get; set; }
        public DateTime ScheduledStart { get; set; }
        public DateTime ScheduledEnd { get; set; }
        public string NoteText { get; set; }
        public ActivityType ActivityType { get; set; }

        public string Save()
        {
            Application tempApp = Application.GetActiveInstance();   <<== Exception At this line
        
            if (tempApp == null)
            {
                tempApp = new Application();
            }
    ...

我在调用 GetActiveInstance 时收到此异常:System.Runtime.InteropServices.COMException: 'Error HRESULT E_FAIL has been returned from a call to a COM component.'

堆栈跟踪:

   at System.Windows.Forms.NativeMethods.IProvideClassInfo.GetClassInfo()
   at System.Windows.Forms.ComponentModel.Com2Interop.Com2TypeInfoProcessor.FindTypeInfo(Object obj, Boolean wantCoClass)

我的谷歌搜索没有返回任何有用的东西,我的头撞在我的桌子上也不起作用。

更新

我将我的项目更改为 32 位并运行它,但在与 64 位相同的位置弹出异常。

标签: c#office365netoffice

解决方案


推荐阅读