Hello,
I hope this is the right group to post this to. I'm trying to serialize a
class I've written and I'd like to be able to serialze to both binary and
xml formats. Binary serialization is working fine but when I try to
instantiate an XmlSerializer object with:
Dim xmls As New XmlSerializer(GetType(CLayerDefinition))
I get the following error:
An unhandled exception of type 'System.InvalidOperationException' occurred
in system.xml.dll
Additional information: There was an error reflecting type
'xmlSerializeTest.CLayerDefinition'.
Can anybody give me some pointer as to why this might be happening since the
error message is not too helpful?
Thanks Steve
The class CLayerDefinition is laid out as:
<Serializable()> _
Public Class CLayerDefinition
Implements IDisposable, IComparable
#Region "Private simple objects"
Private mThemeID As Integer
Private mLayerName As String
Private mThemeName As String
Private mLocation As String
Private mDraw As Boolean
Private mMinScale As Integer
Private mMaxScale As Integer
Private mUserDefined As Boolean
Private mSaved As Boolean
Private mDrawOrder As Integer
Private mLegendType As Integer
Private mSymbolType As Integer
Private mLabelField As String
Private mHasImages As Boolean
Private mRelateTable As String
Private mTableLocation As String
Private mRelateField As String
Private mFileNameField As String
Private mClassItemField As String
Private mNumberOfBreaks As Integer
#End Region
#Region "Private complex objects"
<XmlArray()> _
Private mSymbols() As CLayerSymbol
#End Region
#Region "Public properties"
Public Property NumberOfBreaks() As Integer
Get
Return mNumberOfBreaks
End Get
Set(ByVal Value As Integer)
mNumberOfBreaks = Value
End Set
End Property
Public Property ClassItemField() As String
Get
Return mClassItemField
End Get
Set(ByVal Value As String)
mClassItemField = Value
End Set
End Property
Public Property HasImages() As Boolean
Get
Return mHasImages
End Get
Set(ByVal Value As Boolean)
mHasImages = Value
End Set
End Property
Public Property FileNameField() As String
Get
Return mFileNameField
End Get
Set(ByVal Value As String)
mFileNameField = Value
End Set
End Property
Public Property RelateField() As String
Get
Return mRelateField
End Get
Set(ByVal Value As String)
mRelateField = Value
End Set
End Property
Public Property TableLocation() As String
Get
Return mTableLocation
End Get
Set(ByVal Value As String)
mTableLocation = Value
End Set
End Property
Public Property RelateTable() As String
Get
Return mRelateTable
End Get
Set(ByVal Value As String)
mRelateTable = Value
End Set
End Property
Public Property LabelField() As String
Get
Return mLabelField
End Get
Set(ByVal Value As String)
mLabelField = Value
End Set
End Property
Public Property SymbolType() As Integer
Get
Return mSymbolType
End Get
Set(ByVal Value As Integer)
mSymbolType = Value
End Set
End Property
Public Property LegendType() As Integer
Get
Return mLegendType
End Get
Set(ByVal Value As Integer)
mLegendType = Value
End Set
End Property
Public Property ThemeID() As Integer
Get
Return mThemeID
End Get
Set(ByVal Value As Integer)
mThemeID = Value
End Set
End Property
Public Property LayerName() As String
Get
Return mLayerName
End Get
Set(ByVal Value As String)
mLayerName = Value
End Set
End Property
Public Property ThemeName() As String
Get
Return mThemeName
End Get
Set(ByVal Value As String)
mThemeName = Value
End Set
End Property
Public Property Location() As String
Get
Return mLocation
End Get
Set(ByVal Value As String)
mLocation = Value
End Set
End Property
Public Property DrawOrder() As Integer
Get
Return mDrawOrder
End Get
Set(ByVal Value As Integer)
mDrawOrder = Value
End Set
End Property
Public Property Draw() As Boolean
Get
Return mDraw
End Get
Set(ByVal Value As Boolean)
mDraw = Value
End Set
End Property
Public Property MinScale() As Integer
Get
Return mMinScale
End Get
Set(ByVal Value As Integer)
mMinScale = Value
End Set
End Property
Public Property MaxScale() As Integer
Get
Return mMaxScale
End Get
Set(ByVal Value As Integer)
mMaxScale = Value
End Set
End Property
Public ReadOnly Property UserDefined() As Boolean
Get
Return mUserDefined
End Get
End Property
Public Property Saved() As Boolean
Get
Return mSaved
End Get
Set(ByVal Value As Boolean)
mSaved = Value
End Set
End Property
Public Property Symbols() As CLayerSymbol()
Get
Return mSymbols
End Get
Set(ByVal Value As CLayerSymbol())
mSymbols = Value
End Set
End Property
#End Region
#Region "Public member methods"
Public Sub Dispose() Implements System.IDisposable.Dispose
CleanUp()
GC.SuppressFinalize(Me)
End Sub
Public Function CompareTo(ByVal obj As Object) As Integer Implements
System.IComparable.CompareTo
If TypeOf obj Is CLayerDefinition Then
Dim cld As CLayerDefinition = DirectCast(obj, CLayerDefinition)
mDrawOrder.CompareTo(cld.mDrawOrder)
End If
Throw New ArgumentException("obj is not a CLayerDefintion type")
End Function
#End Region
#Region "Private member methods"
Private Sub CleanUp()
If Not mSymbols Is Nothing Then
If mSymbols.GetUpperBound(0) >= 0 Then
Erase mSymbols
End If
mSymbols = Nothing
End If
End Sub
#End Region
#Region "Constructors"
Public Sub New()
mUserDefined = False
End Sub
Public Sub New(ByVal usrDefined As Boolean)
mUserDefined = usrDefined
End Sub
#End Region
End Class