我正在将一个 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/