F# & COM api 向下转换问题

F# & COM api downcasting issue

我有一些 C# COM Api 示例可以工作,但在转换为 F# 时失败。

F# 代码是:

let list = api.CreateXXX() :?> XXX

C# 转换是隐式的(对象定义变量为 XXX,然后用 api.CreateXxxModule() 初始化它,无需进一步转换。

private XXX list;
[...]
list = api.CreateXXX()

Additional information: Unable to cast COM object of type 'System.__ComObject' to interface type 'ThomsonReuters.Interop.RTX.AdxRtList'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{057B736E-03DF-11D4-99C8-00105AF7EDAD}' failed due to the following error: Cette interface n’est pas prise en charge (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

使用 XXXClass 而不是 XXX 进行向下转换也不起作用:

Additional information: Unable to cast COM object of type 'System.__ComObject' to class type 'XXXClass'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type. Instances of this type cannot be cast to any other class; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

有人将 F# 与通常与 C# 一起使用的 COM Api 一起使用并且对这些类型转换有一些提示吗?

非常感谢!

将 STAThread 属性添加到主函数中:

module Main =

  [<STAThread>] 
  do
    ...