Hi,
I've just started playing around with serialization using the proxy classes.
Serializing has worked great so far but I haven't had the pleasure yet to discover the joy of deserializing ... 
I've read the blog article and tried to apply it in my custom EsCollection classes
When I try to deserialize files I've serialized I get an exception saying : There is an error in XML document (8, 6)
Inner Exception StackTrace:
Code:
at EntitySpaces.Core.esEntityCollection.Add(Object value)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderEthniesCollectionProxyStub.Read7_EthniesCollectionProxyStub(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderEthniesCollectionProxyStub.Read8_EthniesCollectionProxyStub()
Exception StackTrace:
Code:
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
at SampleApplication.BusinessObjects.EthniesCollection.Import(String FileName)
at SampleApplication.ConfigExportImport.Import(String ArchiveFileName)
at SampleApplication.frmImportConfig.BackgroundWorker1_DoWork(Object sender, DoWorkEventArgs e)
Le Code: (exception raising on line 20)
Code:
1 Public Shared Sub Export(ByVal FileName As String)
2
3 Dim Col As New EthniesCollection
4 Col.LoadAll()
5
6 Dim Proxy As New EthniesCollectionProxyStub(Col)
7
8 Dim Serializer As New Xml.Serialization.XmlSerializer(GetType(EthniesCollectionProxyStub))
9 Using Writer As New IO.StreamWriter(FileName, False, System.Text.Encoding.Unicode)
10 Serializer.Serialize(Writer, Proxy)
11 End Using
12
13 End Sub
14 Public Shared Sub Import(ByVal FileName As String)
15
16 Dim Deserializer As New Xml.Serialization.XmlSerializer(GetType(EthniesCollectionProxyStub))
17 Dim Proxy As EthniesCollectionProxyStub
18
19 Using Reader As IO.TextReader = New IO.StreamReader(FileName, System.Text.Encoding.Unicode)
20 Proxy = CType(Deserializer.Deserialize(Reader), EthniesCollectionProxyStub)
21 End Using
22
23 Proxy.Collection.Save()
24
25 End Sub
Le XML File:
Code:
1 <?xml version="1.0" encoding="utf-16"?>
2 <EthniesCollectionProxyStub xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3 <Collection>
4 <Ethnies>
5 <EthnieNum>1</EthnieNum>
6 <EthnieNom>Peulhs</EthnieNom>
7 </Ethnies>
8 <Ethnies>
9 <EthnieNum>2</EthnieNum>
10 <EthnieNom>Wolofs</EthnieNom>
11 </Ethnies>
12 <Ethnies>
13 <EthnieNum>3</EthnieNum>
14 <EthnieNom>Sérères</EthnieNom>
15 </Ethnies>
16 </Collection>
17 </EthniesCollectionProxyStub>
I don't know what really is the problem here, but it seems to me that the esCollectionProxyStub doesn't accept more than a record at a time ? I'm saying this because position (8,6) in the XML file is the begining of the second record.
What should I do to deserialise this properly?
Thanks!
- El pipo -