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

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

问题描述

我试图在C#.NET 4.6.1 WPF项目中添加对"Microsoft Outlook 16.0对象库"的引用,因为我已经安装了Office 2016.早期版本的对象库与2016版的Office不兼容.

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.

如果我使用Excel的VBA编辑器,则会列出"Microsoft Outlook 16.0对象库",并且它存在于C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16010.9126.2116.0_x86_8wekyb3d8bbwe\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\MSOUTL.OLB中,如下所示:

If I use Excel's VBA editor, 'Microsoft Outlook 16.0 Object Library' is listed, and exists in C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16010.9126.2116.0_x86_8wekyb3d8bbwe\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\MSOUTL.OLB, as you can see below:

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

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 Files\WindowsApps, 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'.

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

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

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

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?

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

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.

谢谢.

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

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.

我已经检查了GAC,并且未注册程序集.我已经通过应用和功能"的右键单击开始菜单选项进行了修复,但它们仍然没有出现-好像Windows Store应用只是将其dll推送到Program Files\WindowsApps\*文件夹中,而不是麻烦在GAC中注册它们.

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 Files\WindowsApps\* folder, and don't bother to register them in the GAC.

回答备受赞赏的评论!

使用以下代码

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

如果我使用nuget Microsoft.Office.Interop.Outlook程序包,则会出现System.Runtime.InteropServices.COMException: 'Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))'异常.

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.

如果我尝试通过添加引用"的程序集/扩展"选项卡使用Microsoft Outlook 15.0 Object LibraryMicrosoft Outlook 14.0 Object Library引用,则会出现System.Runtime.InteropServices.COMException: 'Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))'异常.

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.

我不认为要访问WindowsApps文件夹. 首先,它由于某种原因被锁定,这通常表示如果我开始四处挖掘和更改安全权限会带来麻烦,更不用说在解决方案中维护最新dll的副本无疑会给我的项目增加不必要的复杂性.

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.

其次,但更重要的是,如果我已经安装了Office,并且可以从Excel Vba访问"Microsoft Outlook 16.0对象库",那为什么不能从Visual Studio中访问它呢?

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?

显然,安装过程中存在一些问题,无法正确注册dll,只有Excel具有一些技巧,无论如何仍可以使引用可用.

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.

阅读此书的任何人是否能够安装Office 365/2016 Windows Store并在Visual Studio中找到对"Microsoft Outlook 16.0对象库"的引用?

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?

我是唯一遇到这个问题的吗?!因为它会影响我办公室中运行Windows 10和Office 365的多台计算机...

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

要回答RogerN(谢谢),请参见下图-我没有列出Microsoft.Office.Interop.Outlook版本16,也没有列出Microsoft.Office.Core.

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.

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

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

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

*答案是*

我从戴尔购买的两台计算机均为64位,但预装有32位Windows Office版本的MS Office 2016/365.

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:

  • Settings > Apps > Apps&Features > Microsoft Office Desktop Apps > Uninstall
  • 卸载商店应用
  • 登录portal.office.com
  • 选择高级安装Office应用程序,选择64位版本
  • 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

为什么戴尔认为我们希望在64位计算机上安装32位版本,或者为什么Microsoft的某人尚未发布该问题的解决方案,这完全超出了我的理解,但是RogerN是正确的.感谢大家抽出宝贵的时间来帮助我.

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.

推荐答案

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

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.

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

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)互操作(16.0.0.0)的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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