The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Little problem on deserialising

Last post 09-22-2007, 5:21 AM by ElPipo. 13 replies.
Sort Posts: Previous Next
  •  09-20-2007, 6:44 PM 5216

    Little problem on deserialising

    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 ... Stick out tongue

    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 -
  •  09-20-2007, 8:19 PM 5218 in reply to 5216

    Re: Little problem on deserialising

    Please let me know what version of EntitySpaces you are using?

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-20-2007, 8:34 PM 5219 in reply to 5218

    Re: Little problem on deserialising

    I'm using version 2007.0.709.0,    .Net 2.0, visual studio 2005, win xp pro sp2
     


    Thanks!

    - El pipo -
  •  09-21-2007, 4:23 AM 5224 in reply to 5219

    Re: Little problem on deserialising

    There were improvements in both v0730 and v0913 to the proxy classes (see the release notes). They do work perfectly if you get the latest release. My guess is they will work for you in v0709 but if you can I would definitely upgrade to v0913. See this post on our BLOG.

    There is a download link on that post, near the bottom, there is a web service and a client, the client is setup to run directly off of the web services hosted on our site, you can use our proxy to update collections and single objects.


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-21-2007, 8:08 AM 5233 in reply to 5224

    Re: Little problem on deserialising

    Hi,

     so I've upgraded to V0913 but it makes it worse, now all xml files created with the Export method are empty (see code for Export method in first message)  :
     

    Code: xml file created
    <?xml version="1.0" encoding="utf-16"?>
    <EthniesProxyStub xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />

     
    When I step throug the Export method code, I see that the collection is not empty (.count > 0).

     


    Thanks!

    - El pipo -
  •  09-21-2007, 8:26 AM 5234 in reply to 5233

    Re: Little problem on deserialising

    Something's wrong on your end, we can help though. Did you try our demo, it works fine, also, we have lots of folks using these proxies, they do work. Did you regenerate after upgrading? you need to. Are you 100% positive you have the new dlls included, remove the old ones and re-add. I will be out of town this weekend but will help you next week if you don't solve this. I can assure you however that they do work, again, try the demo I pointed to earlier, you can run the client from your machine against our hosted services and use the proxy.

    Also, try without going to disk, like our blogs shows, just do a quick test, serializing and deserializing without going to disk, see what happens?


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-21-2007, 8:34 AM 5235 in reply to 5234

    Re: Little problem on deserialising

    You also need to check the checkbox to preserve state too.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-21-2007, 9:32 AM 5236 in reply to 5234

    Indifferent [:|] Re: Little problem on deserialising

    I had already regenerated my classes, but did it again just to be sure, I had also referenced the 0913 dlls but did it again.

    As I am using VistaDB build 38, I have rebuilt the MyMeta dll for MyGeneration, and also inserted an assembly redirection in my app.config.

    I've tried your demos and they work just fine, I have never doubted they did, it's just that I'm having some trouble implementing this in my app.

    Is there any obvious reason for a proxyStub to generate an xml file containing 0 records when the proxyStub.Collection.Count = 3 ?

    I've noticed something though (please refer to the Export method in first message to clearly locate what I'm talking about):

    in debug mode, I step through the Export method code and hover on the Proxy object: I see that _coll is Nothing but that Collection.count = 3. Is this information of any help? 

     

    I've checked the "preserve state" checkbox, but still get the problem. 


    Thanks!

    - El pipo -
  •  09-21-2007, 11:22 AM 5239 in reply to 5236

    Re: Little problem on deserialising

    I will try, but cannot promise to get to this tonight. I have both your issue and wat's request to look at, althought his is not a bug. If I don't get to this tonight I will get to it Sunday night.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-21-2007, 11:34 AM 5242 in reply to 5239

    Re: Little problem on deserialising

    Thank you very much for taking the time to check on this. I'm flying to a client's site (West Africa) on tuesday and would really appreciate being able to include export/import features in my app by then.

    Thanks!

    - El pipo -
  •  09-21-2007, 4:52 PM 5247 in reply to 5242

    Re: Little problem on deserialising

    I have fixed it. I'll be posting a new template for you in a little while, and better yet, you're code made me realize we can add this to our unit tests. So for now on, starting this release, the ProxyStub's will be completely regression tested in our NUnit test suite, thanx, I'll post back here in a little while. Yes

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-21-2007, 5:10 PM 5248 in reply to 5247

    Re: Little problem on deserialising

    Here is the fix ==> DOWNLOAD

    It contains one template, you just need to overwrite yours, close MyGeneration and unzip this file into C:\Program Files\MyGeneration\Templates\EntitySpaces\VB\Generated assuming you installed MyGeneration into the default folder. The template contained is EntitySpaces_VB_ProxyStubCollection.csgen

    Just regenerate and you should be all set.

    Smile 


     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-22-2007, 3:43 AM 5251 in reply to 5248

    Re: Little problem on deserialising

    Also, after you download the fix above make sure you change your code so that it only calls proxy.GetCollection(), you never use proxy.Collection, that's exposed so it will serialize.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-22-2007, 5:21 AM 5253 in reply to 5251

    Re: Little problem on deserialising

    Thanks for the time and effort you put in it. It's finally working Yes

    The fix fixed the serialization (export) problem but deserializing(import) still raised an exception (XML Error (1,1)). It worked after I modified the code

    From

    Code:
                Dim Deserializer As New Xml.Serialization.XmlSerializer(GetType(EthniesCollectionProxyStub))
    Dim Proxy As EthniesCollectionProxyStub
    Using Reader As IO.TextReader = New IO.StreamReader(FileName, System.Text.Encoding.Unicode)
    Proxy = CType(Deserializer.Deserialize(Reader), EthniesCollectionProxyStub)
    End Using
    Proxy.GetCollection.Save()


    To
     

    Code:
                Dim Deserializer As New Xml.Serialization.XmlSerializer(GetType(EthniesCollectionProxyStub))
    Dim Proxy As EthniesCollectionProxyStub
    Dim fileContents As String fileContents = My.Computer.FileSystem.ReadAllText(FileName) Dim sr As New System.IO.StringReader(fileContents)
    Proxy = CType(Deserializer.Deserialize(sr), EthniesCollectionProxyStub)
    Proxy.GetCollection.Save()

     

    I owe you one.


    Thanks!

    - El pipo -
View as RSS news feed in XML