Xml Deserialization problem in .Net

Xml Deserialization problem in .Net

Post by Jason You » Wed, 28 May 2003 22:10:54



Hello All,

I am having a problem with deserializing (XmlSerializer.Deserialize())
my object using the xml generated from the serialization
(XmlSerializer.Serialize()).  In some cases I can get the xml to feed
into the object I am deserializing, but the object model is
incomplete.  It only seems to find the first object at the lowest
level in my heirarchy, but includes the proper format for the entire
object model.

A few details about my object model.

1) At the lowest level in my object model, I have implemented
IXmlSerializable in order to implement a serialization routine for a
Hashtable which I am using.

2) At higher levels I am not implementing IXmlSerializable.  And have
variouse .Net Attributes strewn throughout the code in order to
control the Xml Generated.

The object serializes to Xml perfectly in just the way that I want it,
but I am disappointed to find that the deserialization has problems.
Is it not safe to say that if it serializes ok then it should
de-serialize as well.

Are there any 'rules' to follow when designing an object model with
the intent to use Xml Serialization in .Net.

Any best practices of object member initialization in the constructor?

Any special attributes needed specifically for deserializing?

The basic object model which I have written is this:

GroupFilter
    GroupFilterConfig
        GroupFilterDependency (implements IXmlSerializable)

An example of the xml that results when i serialize my object is:

<?xml version="1.0" encoding="utf-16"?>
<Filter xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Configs>
    <Config type="OurDataFilterType">
      <Dependencies>
        <Dependency>
          <PMN value="USAXX" desc="USAXX - Nicktown Wireless" />
        </Dependency>
        <Dependency>
          <BID value="04146" desc="04146 - LOS ANGELES, CA" />
          <BID value="40172" desc="40172 - SACRAMENTO, CA" />
          <BID value="04184" desc="04184 - SAN FRANCISCO, CA" />
        </Dependency>
      </Dependencies>
    </Config>
    <Config type="RoamingPartnerDataFilterType">
      <Dependencies>
        <Dependency>
          <PMN value="AGOUT" desc="AGOUT - aaa" />
          <PMN value="ALBAM" desc="ALBAM - bbb" />
          <PMN value="AILID" desc="AILID - ccc" />
        </Dependency>
        <Dependency>
          <BID value="00003" desc="00003 - BUFFALO, NY" />
          <BID value="00001" desc="00001 - CHICAGO, IL" />
          <BID value="00007" desc="00007 - BOSTON, MA" />
        </Dependency>
      </Dependencies>
    </Config>
  </Configs>
</Filter>

When I deserialize the above Xml I get an object back with the
equivalent of:

<Filter xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Configs>
    <Config type="OurDataFilterType">
      <Dependencies>
        <Dependency>
          <PMN value="USAXX" desc="USAXX - Nicktown Wireless" />
        </Dependency>
      </Dependencies>
    </Config>
  </Configs>
</Filter>

Any help or tricks for Xml Serialization in .Net which may solve my
problem would be appreciated.

Thanks,
Jason Young

 
 
 

Xml Deserialization problem in .Net

Post by PJ » Thu, 29 May 2003 10:06:33


Could you post your implementation of IXmlSerializable?  Did you provide a
schema through the GetSchema method?  Is there a way to avoid schema
validation?  Thx...

As for your question, is it a matter of missing state, or are your objects
missing in the serialization all together? I can't help much, but you do
know that xmlserialization only serializes public members by default,
correct?


Quote:> Hello All,

> I am having a problem with deserializing (XmlSerializer.Deserialize())
> my object using the xml generated from the serialization
> (XmlSerializer.Serialize()).  In some cases I can get the xml to feed
> into the object I am deserializing, but the object model is
> incomplete.  It only seems to find the first object at the lowest
> level in my heirarchy, but includes the proper format for the entire
> object model.

> A few details about my object model.

> 1) At the lowest level in my object model, I have implemented
> IXmlSerializable in order to implement a serialization routine for a
> Hashtable which I am using.

> 2) At higher levels I am not implementing IXmlSerializable.  And have
> variouse .Net Attributes strewn throughout the code in order to
> control the Xml Generated.

> The object serializes to Xml perfectly in just the way that I want it,
> but I am disappointed to find that the deserialization has problems.
> Is it not safe to say that if it serializes ok then it should
> de-serialize as well.

> Are there any 'rules' to follow when designing an object model with
> the intent to use Xml Serialization in .Net.

> Any best practices of object member initialization in the constructor?

> Any special attributes needed specifically for deserializing?

> The basic object model which I have written is this:

> GroupFilter
>     GroupFilterConfig
>         GroupFilterDependency (implements IXmlSerializable)

> An example of the xml that results when i serialize my object is:

> <?xml version="1.0" encoding="utf-16"?>
> <Filter xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>   <Configs>
>     <Config type="OurDataFilterType">
>       <Dependencies>
>         <Dependency>
>           <PMN value="USAXX" desc="USAXX - Nicktown Wireless" />
>         </Dependency>
>         <Dependency>
>           <BID value="04146" desc="04146 - LOS ANGELES, CA" />
>           <BID value="40172" desc="40172 - SACRAMENTO, CA" />
>           <BID value="04184" desc="04184 - SAN FRANCISCO, CA" />
>         </Dependency>
>       </Dependencies>
>     </Config>
>     <Config type="RoamingPartnerDataFilterType">
>       <Dependencies>
>         <Dependency>
>           <PMN value="AGOUT" desc="AGOUT - aaa" />
>           <PMN value="ALBAM" desc="ALBAM - bbb" />
>           <PMN value="AILID" desc="AILID - ccc" />
>         </Dependency>
>         <Dependency>
>           <BID value="00003" desc="00003 - BUFFALO, NY" />
>           <BID value="00001" desc="00001 - CHICAGO, IL" />
>           <BID value="00007" desc="00007 - BOSTON, MA" />
>         </Dependency>
>       </Dependencies>
>     </Config>
>   </Configs>
> </Filter>

> When I deserialize the above Xml I get an object back with the
> equivalent of:

> <Filter xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>   <Configs>
>     <Config type="OurDataFilterType">
>       <Dependencies>
>         <Dependency>
>           <PMN value="USAXX" desc="USAXX - Nicktown Wireless" />
>         </Dependency>
>       </Dependencies>
>     </Config>
>   </Configs>
> </Filter>

> Any help or tricks for Xml Serialization in .Net which may solve my
> problem would be appreciated.

> Thanks,
> Jason Young


 
 
 

1. .NET Add-ins in Excel do not show up in Add-ins

Has anyone been successful in adding custom built-in functions into
Excel via the .net XP Interop assemblies?

According to MS KB 316723, you have to make sure you build the
deployment project for the Current User, not the machine.  I did that.

Also, in the Add-in path for Excel, I added a string called "Automation"
(from a support call to Microsoft) ... but
alas ... no add-in after I install.

Anyone get this to work?

--mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

2. HP openview for Solaris 2.x

3. Deserialization problems under .NET Remoting

4. Moving from xp to 2000

5. Typed Datasets - Deserialization problems under .NET Remoting

6. Extended Error 206

7. .NET Add-ins -> Setup project build problems

8. Using winsock.dll outside of Windows?

9. custom object XML deserialization

10. Xml Deserialization: how to detect the target type

11. XML Serialization is giving a strange error on deserialization (System.InvalidOperationException)

12. XML deserialization to Dataset and custom object

13. VB.NET XML Deserialization - can't get at some of the values