.NET RTD / COM Excel互操作错误在一个用户的机器上?

我们在各种机器上构build了一个.NET COM / Excel RTD服务器(.NET程序集),这个程序已经使用了很多年了(也就是说我们知道它的工作原理,以及我们的标准安装方法)。 我们有一个用户在不同的机器上安装了这个RTD组件,并且在顺利运行时遇到问题。 我认为这个问题与Interop.Microsoft.Office.Interop.Excel.dll有关,或者与这台机器不兼容,或者不正确的注册。 以下是具体的细节:

尽pipeRTD链接在某种程度上起作用,但我们发现应用程序经常logging下这个错误:

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.(与他以前的机器相同的configuration文件)。

在此先感谢您的帮助。

与IID接口'{A43788C1-D91B-11D3-8F39-00C04F3651B8}

这是IRTDUpdateEvent接口。 它确实在HKCU \ Interfaces中有一个声明标准编组的条目。 这需要一个types库,LIBID是{00020813-0000-0000-C000-000000000046}。

错误消息告诉你的是,该机器上的registry缺lessregistry项HKCR\TypeLib\{00020813-0000-0000-C000-000000000046}或其某个子项。 这可能是因为它安装了旧版本的Office,但这是显而易见的。 只是简单的registry损坏是这种事故的主要原因。 这是最好的机器,并停止浪费大家的时间。 重新安装Office如果由于某种原因不切实际。 试图修复registry键应该是你的最后一个select,这种损害很less被隔离。

您可能实际上通过调用与Excel相同的线程上的UpdateNotify来解决此问题。 请参阅: https : //stackoverflow.com/a/27006281/949779