I have a VB.NET singleton class which implements Serializable:
Imports System.IO
Imports System.Runtime.Serialization
<Serializable()> Public Class CoordinateHistory
Private Shared _thisInstance As CoordinateHistory
Private gpsHistory As Dictionary(Of DateTime, GpsTimeCoordinate)
Private gpsTimes As List(Of DateTime)
Public Event NewStatusInformation(statusInfo As String)
Protected Sub New()
gpsHistory = New Dictionary(Of DateTime, GpsTimeCoordinate)
gpsTimes = New List(Of DateTime)
End Sub
Public Shared Function getInstance() As CoordinateHistory
If _thisInstance Is Nothing Then
_thisInstance = New CoordinateHistory
End If
Return _thisInstance
End Function
Public Function getHistoryCount() As Integer
Return gpsHistory.Count
End Function
' bunch of other class functions below...
End Class
My problem is that I can’t actually call .Serialize() on the instance of this class, like all of the examples online show. What am I doing wrong? Thanks!
I believe the issue is your Protected Sub. If you change it to Public, you may be able to Serialize correctly.
Update
I didn’t have any issues serializing the default instance using a BinaryFormatter:
or an XMLFormatter:
Perhaps it is the serialization framework you are using?