T
Tony Johansson
Hi!
I have a collection of Movie object stored in a generic list named myList.
private List<Movie> myList = new List<Movie>();
Now I want to XML Serialize this generic list but that doesn't work because
I get Exception se below
Here is my attempt.
private void BtnSeralizeTransformedXML_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("Test.XML", FileMode.Create);
XmlSerializer xs = new XmlSerializer(typeof(Movie));
xs.Serialize(fs, myList);
fs.Close();
}
The runtime Exception I get is this
"InvalidOperationException was unhandled
it was not possible to generate the XML- document"
So why is it not possible to serialize the whole collection of Movie objects
?
[Serializable]
public class Movie
{
private string title = string.Empty;
private string url = string.Empty;
private int runningLength;
private int productionYear;
private long isbnNumber;
public string Title
{
get { return title; }
set { title = value; }
}
public int RunningLength
{
get { return runningLength; }
set { runningLength = value; }
}
public int ProductionYear
{
get { return productionYear; }
set { productionYear = value; }
}
public long IsbnNumber
{
get { return isbnNumber; }
set { isbnNumber = value; }
}
public string Url
{
get { return url; }
set { url = value; }
}
}
//Tony
I have a collection of Movie object stored in a generic list named myList.
private List<Movie> myList = new List<Movie>();
Now I want to XML Serialize this generic list but that doesn't work because
I get Exception se below
Here is my attempt.
private void BtnSeralizeTransformedXML_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("Test.XML", FileMode.Create);
XmlSerializer xs = new XmlSerializer(typeof(Movie));
xs.Serialize(fs, myList);
fs.Close();
}
The runtime Exception I get is this
"InvalidOperationException was unhandled
it was not possible to generate the XML- document"
So why is it not possible to serialize the whole collection of Movie objects
?
[Serializable]
public class Movie
{
private string title = string.Empty;
private string url = string.Empty;
private int runningLength;
private int productionYear;
private long isbnNumber;
public string Title
{
get { return title; }
set { title = value; }
}
public int RunningLength
{
get { return runningLength; }
set { runningLength = value; }
}
public int ProductionYear
{
get { return productionYear; }
set { productionYear = value; }
}
public long IsbnNumber
{
get { return isbnNumber; }
set { isbnNumber = value; }
}
public string Url
{
get { return url; }
set { url = value; }
}
}
//Tony