XmlSerializer.Serialize doesn't save a file and doesn't throw an exception.

Posted by Wodzu on Stack Overflow See other posts from Stack Overflow or by Wodzu
Published on 2010-04-10T18:21:52Z Indexed on 2010/04/10 18:23 UTC
Read the original article Hit count: 245

Filed under:
|
|

Hi guys.

I am having problem with saving of my object. Take a look at this code:

public void SerializeToXML(String FileName)
{
    XmlSerializer fSerializer = new XmlSerializer(typeof(Configuration));
    using (Stream fStream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None))
    {
        fSerializer.Serialize(fStream, this);
    }
}

The problem is that when the user does not have rights to the location on hard disk, this function will not throw me any exception and do not save my file. For example saving to "C:\test.xml" act like nothing happened. And I would like to know if the file has not been saved and it would be good to know the reason why.

I know that I could check if the file on given location exists and throw an exception manualy but shouldn't this be done by the XmlSerializer or FileStream itself?

Thanks for your time

© Stack Overflow or respective owner

Related posts about c#

Related posts about xml-serialization