在 C++/CLI 中
当我尝试序列化包含此属性的类时:
[NonSerialized]
property System::Collections::ObjectModel::ReadOnlyCollection<String^>^ IgnoredWords
我收到编译错误:
致命错误 C1093:API 调用 “定义自定义属性”失败 '0x801311c0'
如何告诉序列化器我不想序列化此属性(是的,默认情况下它会尝试序列化,这会导致运行时错误)?
When I'm trying serialize a class containing this property:
[NonSerialized]
property System::Collections::ObjectModel::ReadOnlyCollection<String^>^ IgnoredWords
I get a compilation error saying:
fatal error C1093: API call
'DefineCustomAttribute' failed
'0x801311c0'
How do I tell the serializer that I do not want to serialize this property (and, yes, by default it tries to, which causes a run time error)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(从 xml-serialization 标记推断)您需要
[XmlIgnore]
作为XmlSerializer
。[NonSerialized]
适用于BinaryFormatter
等,并且仅适用于字段,而不适用于属性(这可能就是您遇到DefineCustomAttribute
失败的原因)。(inferring from xml-serialization tag) You want
[XmlIgnore]
forXmlSerializer
.[NonSerialized]
is forBinaryFormatter
etc, and only applies to fields, not properties (which is probably why you are gettingDefineCustomAttribute
failures).