tags:

views:

25

answers:

1

Type 'ProblemType' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.

I have a class with very little in it. When I try to serialize the class containing it, i get the data contract attribute error, even if the problem type is marked .

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

What can I do to fix this error?

A: 

You should make the backing field a data contract attribute, not the property that uses it.

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
Flo
Still get the same error.
jkerouac
Try marking the whole class as serializable.
Flo