I'm getting the following Exception: There was an error reflecting type 'ValoradorHC.estruturas.dispoHotel'. when i try to Serialize my class
My code is:
Public Function getXMLdeObjecto(ByVal obj As Object)
Dim ser As New XmlSerializer(obj.GetType())
Dim sb As New System.Text.StringBuilder()
Dim writer As New System.IO.StringWriter(sb)
ser.Serialize(writer, obj)
Return sb.ToString()
End Function
The class that i'm trying to serialize:
Public Class estruturas
<Serializable()> _
Public Class PedidoDispo
Private myLocalidade As String
Public mydataInicio As Date
Public mydataFim As Date
Public mynumQuartos As Integer
Public mynumPessoas As Integer
Public myordenar As String
Public myidioma As String
Public Property Localidade() As String
Get
Return myLocalidade
End Get
Set(ByVal Value As String)
myLocalidade = Value.Replace(" ", "_")
End Set
End Property
Public Property dataInicio() As String
Get
Return mydataInicio
End Get
Set(ByVal Value As String)
mydataInicio = Value.Replace(" ", "_")
End Set
End Property
Public Property dataFim() As String
Get
Return mydataFim
End Get
Set(ByVal Value As String)
mydataFim = Value.Replace(" ", "_")
End Set
End Property
Public Property numQuartos() As String
Get
Return mynumQuartos
End Get
Set(ByVal Value As String)
mynumQuartos = Value.Replace(" ", "_")
End Set
End Property
Public Property numPessoas() As String
Get
Return mynumPessoas
End Get
Set(ByVal Value As String)
mynumPessoas = Value.Replace(" ", "_")
End Set
End Property
Public Property ordenar() As String
Get
Return myordenar
End Get
Set(ByVal Value As String)
myordenar = Value.Replace(" ", "_")
End Set
End Property
Public Property idioma() As String
Get
Return myidioma
End Get
Set(ByVal Value As String)
myidioma = Value.Replace(" ", "_")
End Set
End Property
Sub New(ByVal localidade As String, ByVal dataInicio As String, ByVal dataFim As String, ByVal numQuartos As Integer, ByVal numPessoas As Integer)
Me.Localidade = localidade
Me.dataInicio = DateTime.Parse(dataInicio)
Me.dataFim = DateTime.Parse(dataFim)
Me.numQuartos = numQuartos
Me.numPessoas = numPessoas
ordenar = "Popularity-desc"
idioma = "PT"
End Sub
End Class
<Serializable()> _
Public Class dispoHotel
Private myPedido As PedidoDispo
Private mylocalidade As String
Private mylistaHotel As List(Of hotel)
Public ReadOnly Property qtdHotels() As String
Get
Return mylistaHotel.Count
End Get
End Property
Public Property listaHotel() As List(Of hotel)
Get
Return mylistaHotel
End Get
Set(ByVal Value As List(Of hotel))
mylistaHotel = Value
End Set
End Property
Public Property pedido() As PedidoDispo
Get
Return myPedido
End Get
Set(ByVal Value As PedidoDispo)
myPedido = Value
End Set
End Property
Sub New(ByVal pedido As PedidoDispo)
Me.pedido = pedido
listaHotel = New List(Of hotel)
End Sub
Sub New()
listaHotel = New List(Of hotel)
End Sub
End Class
Public Structure hotel
Dim id As String
Dim nome As String
Dim categoria As Integer
Dim morada As String
Dim caracteristicas As List(Of String)
Dim distancia As String
Dim foto As String
Dim melhorPreco As String
Dim precos As Hashtable
End Structure
End Class