无法转换类型为“Microsoft.Office.Interop.Outlook.ApplicationClass"的 COM 对象 {00063001-0000-0000-C000-000000000046} HRESULT: 0x80040155 [英] Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' {00063001-0000-0000-C000-000000000046} HRESULT: 0x80040155

查看:159
本文介绍了无法转换类型为“Microsoft.Office.Interop.Outlook.ApplicationClass"的 COM 对象 {00063001-0000-0000-C000-000000000046} HRESULT: 0x80040155的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一段非常简单的 C# .NET 代码的问题,它应该(目前)只需检索运行 WinForms 应用程序的计算机上安装的 Office 版本号:

I'm having an issue with a very simple piece of C# .NET code which should (for now) simply retrieve the version number of Office installed on the computer running a WinForms application:

var oApp = new Outlook.ApplicationClass();
var outlookVersionString = oApp.Version;

它正确实例化对象,但是当我尝试访问 Version 属性时,我得到以下信息:

It instantiates the object correct, however when I try and access the Version property, I get the following:

{"无法将类型为Microsoft.Office.Interop.Outlook.ApplicationClass"的 COM 对象转换为接口类型Microsoft.Office.Interop.Outlook._Application".此操作失败,因为对由于以下错误,IID 为{00063001-0000-0000-C000-000000000046}"的接口的 COM 组件失败:接口未注册(HRESULT 异常:0x80040155)."}

我在网上做了很多搜索,所以我尝试过的东西:

I've done a lot of searching online, so a run-through of what I've tried:

  1. 检查 [HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}] 中只有一个 Key 存在 (9.6)
  2. [HKEY_CLASSES_ROOT\Interface\{00063001-0000-0000-C000-000000000046}]
  3. 中检查此ClassID和版本是否匹配
  4. 使用 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regtlibv12.exe "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB"注册 MSOUTL.OLB(失败,因为 VS2017 未附带 regtlibv12.exe)
  5. 正在下载 regtlibv12.exe 并重试(失败,因为此应用无法在您的 PC 上运行").
  6. 运行 C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe/TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB"(失败,因为它不是有效的 .NET 程序集)
  7. 运行 C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v2.0.50727\regasm.exe/TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB"(失败,因为它不是有效的 .NET 程序集)
  8. 使用适用于旧互操作库的内容(注意,这似乎不适用于我们的 Office 2016 桌面),这是一个微妙的变化:
  1. Checking that in [HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}] only one Key exists (9.6)
  2. Checking that this ClassID and version matches in [HKEY_CLASSES_ROOT\Interface\{00063001-0000-0000-C000-000000000046}]
  3. Registering MSOUTL.OLB with C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regtlibv12.exe "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB" (fails because regtlibv12.exe isn't shipped with VS2017)
  4. Downloading regtlibv12.exe and trying again (fails because 'This app can't run on your PC').
  5. Running C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB" (fails because it is not a valid .NET Assembly)
  6. Running C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v2.0.50727\regasm.exe /TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB" (fails because it is not a valid .NET Assembly)
  7. Using what worked with the old Interop libraries (edit: note, this does not appear to work with our Office 2016 desktops), which is a subtle change:

var oApp = new Outlook.Application();var OutlookVersionString = oApp.Version;

值得注意的是,我有一个干净的 Windows 10 Enterprise N Creators Update 和 Office 2016/365 ProPlus,没有安装任何以前的版本,也没有降级.

It might be worth noting that I have a clean Windows 10 Enterprise N Creators Update, and Office 2016 / 365 ProPlus, haven't had any previous versions installed, and haven't downgraded.

我通常不是桌面应用程序开发人员,所以虽然我掌握了其中一些库注册工具,但我绝不是专家..

I'm not normally a desktop app developer so while I grasp some of these library registration tools, I'm by no means an expert..

推荐答案

尝试修复"您的 Microsoft Office 安装.转到程序和功能",选择修改",然后选择在线修复".我遇到了同样的问题,这个问题解决了.

Try to "repair" your Microsoft Office installation. Go to Programs and Features, select Modify and then Repair Online. I had the same issue and this fixed it.

这篇关于无法转换类型为“Microsoft.Office.Interop.Outlook.ApplicationClass"的 COM 对象 {00063001-0000-0000-C000-000000000046} HRESULT: 0x80040155的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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