Strange problem with XmlSerializer creating duplicate end tags

S

sklett

I have several objects that I'm saving to disk via the XmlSerializer. 80% of
the time this works fine, but occasionaly it will create a file like this:

<?xml version="1.0"?>
<SystemOptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<AssetDirectory>C:\Documents and Settings\sklett\Local
Settings\Temp\</AssetDirectory>
<ProductLabelPrinter>Adobe PDF</ProductLabelPrinter>
</SystemOptions>
</SystemOptions>

Note the double </SystemOptions> tags. Anyone ever run into this?

Here is the code doing the serialization in case it helps:
<code>

public void Save()
{
using (FileStream stream = File.Open(FullPath,
FileMode.OpenOrCreate, FileAccess.Write))
{
_serializer.Serialize(stream, this);
stream.Close();
}
}

</code>

Thanks for reading,
Steve
 
M

Marc Gravell

It sounds to me like the second tag was left-overs from the file
contents previous... i.e. you have over-written part of the file
(only).

Have you tried deleting the file first and starting from fresh?

Marc
 
S

sklett

Deleting is a good idea, I never thought of that. I haven't used
XmlSerialization much and when I have it always works so well (too easy
maybe) that I just figured it would "take care of everything and work
perfect" :)

I've added code to delete the file first, hopefully that solves it, makes
sense that it would.
Thanks for the suggestion!
 
M

Marc Gravell

XmlSerializer is doing its job just fine; FileStream is the culprit
here

Marc
 

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