一个用户计算机上的 .NET RTD/COM Excel 互操作错误
本文关键字:RTD NET COM Excel 错误 互操作 一个 计算机 用户 | 更新日期: 2023-09-27 18:31:30
我们构建了一个.NET COM/Excel RTD服务器(.NET Assembly),该服务器已经在各种机器上使用了很多年(即我们知道它有效,并且我们的标准安装方法有效)。 我们有一个用户在另一台机器上安装了这个 RTD 组件,但在使其顺利运行时遇到了问题。 我相信问题与Interop.Microsoft.Office.Interop.Excel有关.dll不知何故与这台机器不兼容,或者注册不正确。 以下是具体细节:
尽管RTD链接在某种程度上可以正常工作,但我们会看到应用程序经常记录此错误:
RTDServer.NotifyExcel(): Error notifying Excel, ex=System.InvalidCastException:
Unable to cast COM object of type 'System.__ComObject' to interface type
'Microsoft.Office.Interop.Excel.IRTDUpdateEvent'. This operation failed because
the QueryInterface call on the COM component for the interface with
IID '{A43788C1-D91B-11D3-8F39-00C04F3651B8}' failed due to the following error:
Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
at Microsoft.Office.Interop.Excel.IRTDUpdateEvent.UpdateNotify()
at EZomsRTDServer.RTDServer.NotifyExcel()
当我在用户的计算机上进行故障排除时,我检查了我们的组件是否已在 COM 中正确注册。 我们运行以下命令以将组件注册到 COM:
C:'EZomsRTD'regasm EZomsRTDServer.dll /codebase "c:'EZomsRTD'EZomsRTDServer.dll"
C:'EZomsRTD'regasm EZomsRTDServer.dll /tlb
在用户的机器上运行这些命令会产生以下 regasm 错误:
Type library exporter warning: Referenced type is defined
in managed component, which is imported from a type library
that could not be loaded because it was not registered
(type: 'Microsoft.Office.Interop.Excel.IRtdServer'; component:
'C:'EZomsRTD'Interop.Microsoft.Office.Interop.Excel.dll').
Assembly exported to 'C:'EZomsRTD'EZomsRTDServer.tlb', and the type
library was registered successfully
(文件:Interop.Microsoft.Office.Interop.Excel.dll与我们的组件位于同一文件夹中。
这是否可能是由于在此计算机的 GAC 中注册了另一个版本的 Interop.Excel 程序集引起的? 还有其他可能要调查的领域吗?
注意:用户具有Windows XP和Excel 2003。(与他以前的机器相同的配置文件。
提前感谢任何帮助。
接口与 IID '{A43788C1-D91B-11D3-8F39-00C04F3651B8}
这就是 IRTDUpdateEvent 接口。 它确实在 HKCU''Interfaces 中有一个条目,用于声明标准编组器。 这需要一个类型库,LIBID 是 {00020813-0000-0000-C000-000000000046}。
错误消息告诉您的是,该计算机上的注册表缺少注册表项HKCR'TypeLib'{00020813-0000-0000-C000-000000000046}
或其子项之一。 这可能是因为它安装了旧版本的Office,但这是显而易见的。 只是普通的注册表损坏是此类事故的主要原因。 最好把机器扔掉,让它停止浪费每个人的时间。 如果由于某种原因不切实际,请重新安装 Office。 尝试修复注册表项应该是您的最后选择,这种损坏很少被隔离。
实际上,您可以通过在与Excel相同的线程上调用UpdateNotify来解决此问题。请参阅:https://stackoverflow.com/a/27006281/949779