c# - 更改框架 4.0 中数组的 Com Interop 表示?

标签 c# com interop

我正在将一个 C# web 项目从 2.0 框架升级到 4.0 框架,我似乎在它引用的 COM 组件周围遇到了一些问题。似乎在互操作的生成过程中发生了一些我不知道的变化。

在不更改任何代码的情况下,我现在遇到了很多如下错误:

cannot convert from 'out string[]' to 'out System.Array'

对于上面的第一个错误,这是原型(prototype):

[id(3), helpstring("method GetAllWaves")] HRESULT GetAllWaves([out] SAFEARRAY(BSTR)* ppWaves,  [out,retval] ExactaStatus *Status);

这是使用它的 C# 代码:

string[] arrWaves;

m_BPStatus = m_objTXPBatchPick.GetAllWaves(out arrWaves);

似乎 visual studio 现在正在根据我之前使用的相同 COM 库生成不同的方法原型(prototype),并且它使用的是 System.Array 而不是特定类型。这是关于 4.0 项目的新内容还是我在 visual studio 中缺少某些设置?

最佳答案

我从来没有找到解决这个问题的办法。我必须进行以下代码更改:

Array arrWaves;

m_BPStatus = m_objTXPBatchPick.GetAllWaves(out arrWaves);
Session["arrWaves"] = arrWaves.Cast<string>().ToArray();

上面的关键是将其更改为将其存储为.Cast<string>().ToArray()

关于c# - 更改框架 4.0 中数组的 Com Interop 表示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34209246/

相关文章:

c# - 对于接口(interface) : T[], IEnumerable<T>、IList<T> 或其他接口(interface),您更喜欢哪个?

c# - 带有枚举的无效初始值设定项成员类

com - 如何使用 WiX 将 dll 注册到 COM 安装后

c# - 将 C# 类数组作为结构数组编码到 C

python - Clojure Jython 互操作

c# - 返回与正则表达式匹配的有限集

c# - 如何从 View 一次更新多行(ASP.NET - 核心)

windows - 如何获取已注册COM接口(interface)的IID?

c# - 当 "Class not registered"时,实例化 COM 组件失败并显示 "Run As Administrator"

c# - 向 Windows 进程(不是它的主窗口)发送消息