Link to home
Start Free TrialLog in
Avatar of Charles Baldo
Charles BaldoFlag for United States of America

asked on

must declare a body because it is not marked abstract or extern

Hi I am a newbie and am getting this error when trying to learn xml serialization

Error 1      'XMLSerialize.Movie.Title.get' must declare a body because it is not marked abstract or extern C:\XMLSerializer\XMLSerializer\Program.c

I have attached the code snippet, could anyone please tell me why and what to do to fix?

Thank You
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
 
namespace XMLSerialize
{
    public class MainClass
    {
 
        static void Main(string[] args)
        {
            Movie movie = new Movie();
            movie.Title = "Starship Troopers";
            movie.ReleaseDate = DateTime.Parse("11/7/1997");
            movie.Rating = 6.9f;
 
            SerializeToXML(movie);
        }
 
        static public void SerializeToXML(Movie movie)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Movie));
            TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
            serializer.Serialize(textWriter, movie);
            textWriter.Close();
        }
    }
 
 
    public class Movie
    {
        public string Title
        {
            get; set;
        }
 
        public int Rating
        { get; set; }
 
        public DateTime ReleaseDate
        { get; set; }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
one more thing for .Net 2.0
initialize all your strings else they will not be serialized on serialization if the members are null
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well that's what I get for using VS .Net 3.5. Snarf0001 is correct about auto-implemented properties. ;==)
Avatar of Charles Baldo

ASKER

thanks a ton Snarf0001, Thanks fernando as well as catching data type mismatch