c# - 使用 C# 中的 COM 属性时出现错误 CS1545
问题描述
我创建了具有读/写属性的 COM 接口:
[
object,
uuid(...),
dual,
pointer_default(unique)
]
IInterfaceWithProperty : IDispatch
{
[propget, id(1)] HRESULT Property([out, retval] IInterface2** ppObject);
[propput, id(1)] HRESULT Property([in] IInterface* pObject);
};
当尝试在 C# 中使用时:
var value = object.Property;
object.Property = value;
收到以下错误:
error CS1545: Property, indexer, or event 'IInterfaceWithProperty .Property' is not supported
by the language; try directly calling accessor methods
'IInterfaceWithProperty.get_Property()' or
'IInterfaceWithProperty.set_Property(IInterface)'
可能是什么原因?
解决方案
错误的原因是属性在 getter 和 setter 中应该具有相同的类型。
将 IInterfaceWithProperty 更改为
[
object,
uuid(...),
dual,
pointer_default(unique)
]
IInterfaceWithProperty : IDispatch
{
[propget, id(1)] HRESULT Property([out, retval] IInterface2** ppObject);
[propput, id(1)] HRESULT Property([in] IInterface2* pObject);
};
问题消失了。
推荐阅读
- bash - tmux:在窗格中运行命令并在 bash 脚本中捕获结果
- javafx - JavaFX(场景生成器)箭头键 OnKeyPressed
- node.js - 运行“npm install”后,Docker 构建(Windows)挂起
- yii2 - 如何根据 Yii2 中的 radioList 更改显示/隐藏 div 框?
- loops - 使用ffmpeg批量处理文件夹中的所有文件?
- video-streaming - 媒体基金会:英特尔硬件 MFT 的 SPS/PPS 问题
- flowground - 我需要在 flowground 中使用某种决策模块
- python - 如何在 Python 中的 Pandas Dataframe 标头上设置边框
- xml - 使用 sweet_xml 在 Elixir 中解析 xml(编码 utf-16)
- python - 读取带有由双换行符分隔的元素的降价文件