Microsoft.Office.Interop.Excel has the IRtdServer interface.
This interface is imported into a server app as
<ComImport(), Guid("EC0E6191-DB51-11D3-8F3E-00C04F3651B8"),
InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IRtdServer
<DispId(10)>
Function ServerStart(callback As IRTDUpdateEvent) As Integer
<DispId(11)>
Function ConnectData(topicId As Integer, <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_VARIANT)> ByRef strings As Array, ByRef newValues As Boolean) As Object
<DispId(12)>
Function RefreshData(ByRef topicCount As Integer) As <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_VARIANT)> Array
<DispId(13)>
Sub DisconnectData(topicId As Integer)
<DispId(14)>
Function Heartbeat() As Integer
<DispId(15)>
Sub ServerTerminate()
End Interface
The RTD server works fine with Microsoft Excel.
This interface is also imported into a client app that uses the server.
The code to create the server instance:
Dim serverType As Type = Type.GetTypeFromProgID(progID)
Dim obj As Object = Activator.CreateInstance(serverType, True)
Dim server As IRtdServer = CType(obj, IRtdServer)
This code raises the cast exception:
Unable to cast object of type '...' to type 'TestConsole.IRtdServer'.
It seems that the compiler do not use the COM interface declaration and use the client assembly type.
Excel works with the server correctly. So, the problem is in the client code...
Please help.
VS 2010, .NET 4.0.