类型'ProblemType'无法序列化。请考虑使用DataContractAttribute属性对其进行标记,并使用DataMemberAttribute属性标记要序列化的所有成员。有关其他受支持的类型,请参阅Microsoft .NET Framework文档。
我的课程很少。当我尝试序列化包含它的类时,即使问题类型被标记,我也会收到数据协定属性错误。
Imports System
Imports System.Runtime.Serialization
<DataContractAttribute()> _
Public Class ProblemType
Implements ICloneable
private _serializablePropertyBacking as byte
<DataMemberAttribute()> _
Public Property SerializableProperty() As Byte
Get
Return _serializablePropertyBacking
End Get
Set(ByVal Value As Byte)
_serializablePropertyBacking = Value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(byval option as boolean)
If option Then
_serializableProperty = 1
End If
End Sub
End Class
我该怎么做才能解决此错误?
答案 0 :(得分:0)
您应该将支持字段设置为数据协定属性,而不是使用它的属性。
Imports System
Imports System.Runtime.Serialization
<DataContractAttribute()> _
Public Class ProblemType
Implements ICloneable
<DataMemberAttribute()> _
private _serializablePropertyBacking as byte
Public Property SerializableProperty() As Byte
Get
Return _serializablePropertyBacking
End Get
Set(ByVal Value As Byte)
_serializablePropertyBacking = Value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(byval option as boolean)
If option Then
_serializableProperty = 1
End If
End Sub
End Class