无法添加对 Outlook 2016 (Office 365) Interop (16.0.0.0) 的引用 [英] Cannot add reference to Outlook 2016 (Office 365) Interop (16.0.0.0)

查看:51
本文介绍了无法添加对 Outlook 2016 (Office 365) Interop (16.0.0.0) 的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 C# .NET 4.6.1 WPF 项目中添加对Microsoft Outlook 16.0 对象库"的引用,因为我安装了 Office 2016.以前版本的对象库与 2016 版的 office 不兼容.

如果我使用 Excel 的 VBA 编辑器,则会列出Microsoft Outlook 16.0 对象库",并且存在于 C:Program FilesWindowsAppsMicrosoft.Office.Desktop_16010.9126.2116.0_x86_8wekyb3d8bbweVFSProgramFilesShareCommonX86MicrosoftOFFICE16MSOUTL.OLB,如下所示:

但是,当我使用 Visual Studio 时,COM 选项卡没有列出Microsoft Office 16.0 对象库",当我尝试浏览到 C:Program FilesWindowsApps 时,我得到 '您当前没有访问此文件夹的权限",单击继续"(以获取访问权限)会导致您被拒绝访问此文件夹的权限".

因此,基本上,Office 2016 dll 似乎已隐藏在一个人、狗和本地管理员无法访问的文件夹中.

<小时>

我要做的就是连接到打开的 Outlook 应用程序,然后发送一封带有附件的电子邮件,所以也许要问的另一个问题是,是否有一些与 Outlook 2016 通信的新奇方式没有出现在我的 Googleathon 中?

<小时>

另外值得注意的是,我的 Office 版本是作为Windows 应用商店应用程序"安装的,因此不会出现在通常的添加/删除程序列表中,因此我找不到任何用于安装的修复"选项.

谢谢.

<小时>

进一步的调查表明我做的是正确的事情 - 尝试添加对Microsoft Outlook 16.0 对象库"的 COM 引用现在是针对 Outlook 的正确方法......

如果我尝试使用 v15 库,则会收到以下错误:

System.Runtime.InteropServices.COMExceptionHResult=0x80040154消息=检索具有 CLSID {0006F03A-0000-0000-C000-000000000046} 的组件的 COM 类工厂由于以下错误而失败:80040154 类未注册(来自 HRESULT 的异常:0x80040154 (REGASSDREG_E)).源=mscorlib

<小时>

*答案是*

我从戴尔购买的两台计算机是 64 位的,但它们预装了 32 位 Windows 商店版本的 MS Office 2016/365.

为了解决这个问题,我不得不:

  • 设置>卸载商店应用程序应用程序应用程序和功能 >Microsoft Office 桌面应用程序 >卸载
  • 登录portal.office.com
  • 选择安装办公应用,高级,选择 64 位版本

为什么戴尔认为我们希望在 64 位机器上安装 32 位版本,或者为什么 Microsoft 的某个人没有发布解决此问题的方法,这超出了我的理解,但无论如何,RogerN 是正确的.感谢大家抽出时间帮助我.

解决方案

详细说明我之前的评论:根据您的描述,听起来您已经在 64 位上安装了 32 位版本的 Microsoft Office机器.只会注册 32 位 COM 对象,因此 64 位 .NET 应用程序将无法找到它们.如果您搜索您的注册表,您应该会发现 0006F03A-0000-0000-C000-000000000046 类 ID 仅注册在 Wow6432Node 下.

要解决此问题,您可以安装 64 位版本的 Office,也可以强制您的 .NET 应用程序面向 x86 平台.

I'm trying to add a reference to 'Microsoft Outlook 16.0 Object Library' in a C# .NET 4.6.1 WPF project, because I have office 2016 installed. Previous versions of the Object Library are incompatible with the 2016 version of office.

If I use Excel's VBA editor, 'Microsoft Outlook 16.0 Object Library' is listed, and exists in C:Program FilesWindowsAppsMicrosoft.Office.Desktop_16010.9126.2116.0_x86_8wekyb3d8bbweVFSProgramFilesCommonX86Microsoft SharedOFFICE16MSOUTL.OLB, as you can see below:

However, when I use Visual Studio, the COM tab does not list 'Microsoft Office 16.0 Object Library', and when I try to browse to C:Program FilesWindowsApps, i get 'You dont currently have permission to access this folder', and clicking 'Continue' (to get access) results in 'You have been denied permission to access this folder'.

So basically, the Office 2016 dlls seem to have been tucked away in a folder that is inaccessible to man, dog, and local administrator.


All I'm trying to do is connect to the open Outlook application, and then send an email with an attachment, so perhaps another question to ask is, is there some new fangled way to communicate with Outlook 2016 that hasn't cropped up in my Googleathon?


Also worth noting is that my version of office is installed as a 'Windows Store Application' and therefore does not appear on the usual Add/Remove programs list, so I can't find any 'repair' options for the installation.

Thanks.


Further investigation reveals that I am doing the right thing - trying to add a COM reference to 'Microsoft Outlook 16.0 Object Library' is now the correct way to target Outlook ... https://stackoverflow.com/a/21018418/5040941.

I've checked the GAC, and the assemblies aren't registered. I've done a repair via the 'Apps and Features' right-click start menu option, and they still aren't appearing - it's as if the Windows Store apps just shove their dlls into the Program FilesWindowsApps* folder, and don't bother to register them in the GAC.


In answer to the much appreciated comments!

Using the following code

Outlook.Application application = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");

If I use the nuget Microsoft.Office.Interop.Outlook package, i get a System.Runtime.InteropServices.COMException: 'Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))' exception.

If I try using Microsoft Outlook 15.0 Object Library or Microsoft Outlook 14.0 Object Library references via the Assemblies/Extensions tab of Add Reference, I get a System.Runtime.InteropServices.COMException: 'Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))' exception.

I don't think accessing the WindowsApps folder is the way to go. Firstly, it's locked down for some reason which typically indicates the potential for trouble if i start digging around and changing security permissions, not to mention the fact that maintaining a copy of the latest dll in my solution will undoubtedly add unnecessary complexity to my project.

Secondly, but more importantly, if I have office installed, and I can access 'Microsoft Outlook 16.0 Object Library' from Excel Vba, then why can't I access it from Visual Studio?

There is obviously some issue with the installation not registering the dlls properly, only Excel has some trick it uses to make the reference available anyway.


Has anyone reading this managed to install Office 365/2016 Windows Store and found a reference to 'Microsoft Outlook 16.0 Object Library' in Visual Studio?

Am I the only with this problem?! Because it affects multiple computers in my office running Windows 10 and Office 365 ...


In answer to RogerN (thanks), please see the image below - I don't have Microsoft.Office.Interop.Outlook version 16 listed, and Microsoft.Office.Core isn't listed either.

If I try to use the v15 library, I get the following error:

System.Runtime.InteropServices.COMException HResult=0x80040154 Message=Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). Source=mscorlib


*AND THE ANSWER IS *

The two computers I bought from Dell are 64 bit, but they come preinstalled with 32 bit, windows store versions of MS Office 2016/365.

In order to fix the problem, I had to:

  • uninstall the store app from Settings > Apps > Apps&Features > Microsoft Office Desktop Apps > Uninstall
  • log into portal.office.com
  • select install office apps, advanced, choosing the 64-bit version

Quite why Dell think we want 32 bit versions installed on 64 bit machines, or why someone from Microsoft hasn't posted a solution to this problem, is beyond my understanding, but nevertheless, RogerN was correct. Thanks to everyone for taking time out their days to help me out.

解决方案

Elaborating on my earlier comment: From what you've described, it sounds like you've installed a 32-bit version of Microsoft Office on a 64-bit machine. Only 32-bit COM objects would have been registered, and therefore a 64-bit .NET application would be unable to find them. If you search your registry, you ought to find that the 0006F03A-0000-0000-C000-000000000046 class ID is only registered under the Wow6432Node.

To resolve the issue, you could either install the 64-bit version of Office or force your .NET application to target the x86 platform.

这篇关于无法添加对 Outlook 2016 (Office 365) Interop (16.0.0.0) 的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆