XML Deserializer problem

S

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/li...tion.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.
 
F

Family Tree Mike

Skitsanos said:
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="(e-mail address removed)" />
</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.
 
S

Skitsanos

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top