无法转换类型为“Microsoft.Office.Interop.Outlook.ApplicationClass”的 COM 对象 {00063001-0000-0000-C000-000000000046} HRESULT:0x80040155

问题描述 投票:0回答:4

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

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

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

{"Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type 'Microsoft.Office.Interop.Outlook._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063001-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155)."}

我在网上做了很多搜索,所以总结一下我所尝试过的:

  1. 检查
    [HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}]
    中是否只有一个Key存在(
    9.6
    )
  2. 检查此 ClassID 和版本是否匹配
    [HKEY_CLASSES_ROOT\Interface\{00063001-0000-0000-C000-000000000046}]
  3. 使用
    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)
  4. 下载 regtlibv12.exe 并重试(失败,因为“此应用程序无法在您的电脑上运行”)。
  5. 运行
    C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB"
    (失败是因为
    is not a valid .NET Assembly
  6. 运行
    C:\Users\uczms>c:\Windows\Microsoft.NET\Framework64\v2.0.50727\regasm.exe /TLB "C:\Program Files (x86)\Microsoft Office\root\Office16\MSOUTL.OLB"
    (失败是因为
    is not a valid .NET Assembly
  7. 使用与旧的 Interop 库兼容的内容(编辑:注意,这似乎不适用于我们的 Office 2016 桌面),这是一个微妙的变化:

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

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

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

c# .net outlook ms-office
4个回答
7
投票

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


3
投票

我很欣赏这是一个“旧”主题,我的问题是 Visual Studio 在 .NET Framework 4.5+ 的项目编译属性中默认为“首选 32 位”。 ! Visual Studio 首选 32 位复选框的屏幕截图:


Screenshot of Visual Studio Prefer 32-bit checkbox


2
投票
3“确保 MSOUTL.LIB 已注册”

webmakers - 接口未注册(HRESULT 的异常:0x80040155) – Microsoft Office/Outlook 错误,检查前一点后,很明显。 感谢 Jatin-Auckland 提供清晰的分步指南。 祝你好运;)


0
投票

© www.soinside.com 2019 - 2024. All rights reserved.