Home All Groups Group Topic Archive Search About

XML Deserializer problem

Author
25 Nov 2007 7:50 PM
Skitsanos
Guys,

Have very strange issue with deserialization. Really need help,
because i just don't getting why the hell this not works in a way it
suppose to be.

Here is the sample object i serialize into XML:

<XmlRoot("CONTACTS")> _
    Public Class Contacts
        <XmlAttribute("version")> Public Version As String = "0.2"

        <XmlElement(Type:=GetType(OrganizationType),
ElementName:="ORGANIZATION", IsNullable:=False,
Form:=XmlSchemaForm.Qualified), _
                 EditorBrowsable(EditorBrowsableState.Advanced)> _
                 Public __Organizations As OrganizationColectionType

        <XmlIgnore()> _
        Public Property Organizations() As OrganizationColectionType
            Get
                If __Organizations Is Nothing Then __Organizations =
New OrganizationColectionType()
                Organizations = __Organizations
            End Get
            Set(ByVal Value As OrganizationColectionType)
                __Organizations = Value
            End Set
        End Property
    End Class

Deseriliazing i do via this function:

    Public Function SetXml(ByVal obj As Object, ByVal XmlData As
String) As Object
        Dim ser As New XmlSerializer(obj.GetType)
        Dim ms As New
IO.MemoryStream(Text.Encoding.UTF8.GetBytes(XmlData))
        Dim xr As New Xml.XmlTextReader(ms)
        Debug.WriteLine("Can deserialize: " +
ser.CanDeserialize(xr).ToString)
        Return ser.Deserialize(xr)
    End Function

On ser.CanDeserialize it always return /TRUE/ that i assume tells that
source XML is fine. At least it says "Gets a value that indicates
whether this XmlSerializer can deserialize a specified XML document."
on http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.candeserialize(VS.80).aspx

But problem is that actual deserialization is never happens. Object
not getting filled with data from XML.

If i take any other object to deserialize, i get my data, but objects
build like this are failed.

Is anyone have any idea wtf is wrong?

Cheers,
Evi.

Author
26 Nov 2007 1:01 AM
Family Tree Mike
Does the xml string look as you expect?

Show quoteHide quote
"Skitsanos" wrote:

> Guys,
>
> Have very strange issue with deserialization. Really need help,
> because i just don't getting why the hell this not works in a way it
> suppose to be.
>
> Here is the sample object i serialize into XML:
>
> <XmlRoot("CONTACTS")> _
>     Public Class Contacts
>         <XmlAttribute("version")> Public Version As String = "0.2"
>
>         <XmlElement(Type:=GetType(OrganizationType),
> ElementName:="ORGANIZATION", IsNullable:=False,
> Form:=XmlSchemaForm.Qualified), _
>                  EditorBrowsable(EditorBrowsableState.Advanced)> _
>                  Public __Organizations As OrganizationColectionType
>
>         <XmlIgnore()> _
>         Public Property Organizations() As OrganizationColectionType
>             Get
>                 If __Organizations Is Nothing Then __Organizations =
> New OrganizationColectionType()
>                 Organizations = __Organizations
>             End Get
>             Set(ByVal Value As OrganizationColectionType)
>                 __Organizations = Value
>             End Set
>         End Property
>     End Class
>
> Deseriliazing i do via this function:
>
>     Public Function SetXml(ByVal obj As Object, ByVal XmlData As
> String) As Object
>         Dim ser As New XmlSerializer(obj.GetType)
>         Dim ms As New
> IO.MemoryStream(Text.Encoding.UTF8.GetBytes(XmlData))
>         Dim xr As New Xml.XmlTextReader(ms)
>         Debug.WriteLine("Can deserialize: " +
> ser.CanDeserialize(xr).ToString)
>         Return ser.Deserialize(xr)
>     End Function
>
> On ser.CanDeserialize it always return /TRUE/ that i assume tells that
> source XML is fine. At least it says "Gets a value that indicates
> whether this XmlSerializer can deserialize a specified XML document."
> on http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.candeserialize(VS.80).aspx
>
> But problem is that actual deserialization is never happens. Object
> not getting filled with data from XML.
>
> If i take any other object to deserialize, i get my data, but objects
> build like this are failed.
>
> Is anyone have any idea wtf is wrong?
>
> Cheers,
> Evi.
>
Author
26 Nov 2007 6:40 AM
Skitsanos
On Nov 26, 3:01 am, Family Tree Mike
<FamilyTreeM***@discussions.microsoft.com> wrote:
> Does the xml string look as you expect?

Yes, it looks very fine. The actual serialization output is this:

<CONTACTS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="0.2">
  <ORGANIZATION name="Org1" shortName="org1">
    <PERSON firstName="John" lastName="Doe"
emailAddress="j***@local.vpn" />
  </ORGANIZATION>
  <ORGANIZATION name="Org2" shortName="org2" />
</CONTACTS>
Author
26 Nov 2007 11:40 AM
Family Tree Mike
"Skitsanos" wrote:

> Yes, it looks very fine. The actual serialization output is this:
>
> <CONTACTS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="0.2">
>   <ORGANIZATION name="Org1" shortName="org1">
>     <PERSON firstName="John" lastName="Doe"
> emailAddress="j***@local.vpn" />
>   </ORGANIZATION>
>   <ORGANIZATION name="Org2" shortName="org2" />
> </CONTACTS>
>

What does your call to SetXml() look like?  I'm guessing it looks like this,
but I don't want to assume that it does:

Contact2 = SetXml(Contact1, theXmlString)  ' note, contact1 is not changed
in this call, only used to get the data type.
Author
26 Nov 2007 12:52 PM
Skitsanos
On 26 Noi, 13:40, Family Tree Mike
<FamilyTreeM***@discussions.microsoft.com> wrote:
> What does your call to SetXml() look like?  I'm guessing it looks like this,
> but I don't want to assume that it does:
>
> Contact2 = SetXml(Contact1, theXmlString)  ' note, contact1 is not changed
> in this call, only used to get the data type.

damn, im the one who screwed it;) thanx man. i just didn't paid enough
attention to my own code, silly.