C# Serializing data in an XML file

Code with C | Programming: Projects & Source Codes Forums C# Programming C# Serializing data in an XML file

This topic contains 1 reply, has 1 voice, and was last updated by  SapnaVishwas 2 years, 7 months ago.

  • Author
    Posts
  • #10738

    Aleisha
    Member

    I’m having some troubles serializing data in an XML-file using C#..
    Basicly, I want to serialize data in a Linked List using the xmlSerializer:

    Here’s what I have so far:

    “head” is my first node of the linked list, so I wanted to try it out with just one node first.
    But, the program gives neither an error or an XML-file.
    is there something I’m forgetting or missing?

    And yes, this is for a project for school, but I’ve looked up serialization everywhere and nothing helps.

    Same goes for the teachers, it’s a DIY-project, no help from school.

  • #10739

    SapnaVishwas
    Member

    First thing: Is directory 'C:\temp' exist? If not, StreamWriter constructor will break execution of your function on line 2. You can catch that exception if you surround your code with try-catch block (that even recommended for I/O operations)

    Second thing: You not close your stream. StreamWriter is buffered by default, meaning it won’t output until it receives a Flush() or Close() call.
    So proper code should look something like this:

    Last thing: Default serialization had some limitation, if above tips dont help, post code of ‘head’ object class.

You must be logged in to reply to this topic.