Помогите настроить XML сериализацию. Выдает такое exception:
Необработанное исключение типа "System.InvalidOperationException" в System.Xml.dll
Дополнительные сведения: В документе XML (2, 2) присутствует ошибка.
За любые замечания по коду так же буду благодарен.
<?xml version="1.0"?>
<ArrayOfMovie xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Movie>
<Title>Alien</Title>
<Year>1979</Year>
<Rating>8.8</Rating>
<Director>Ridley Scott</Director>
</Movie>
<Movie>
<Title>The Matrix</Title>
<Year>1999</Year>
<Rating>8.7</Rating>
<Director>Wachowski Brothers</Director>
</Movie>
<Movie>
<Title>Inception</Title>
<Year>2010</Year>
<Rating>8.8</Rating>
<Director>Christopher Nolan</Director>
</Movie>
<Movie>
<Title>Interstellar</Title>
<Year>2014</Year>
<Rating>8.7</Rating>
<Director>Christopher Nolan</Director>
</Movie>
</ArrayOfMovie>
public class XMLSerialization<T> : IXMLSerialization<T>
{
public XMLSerialization() { }
public void ToXml(string filename, T data)
{
if (File.Exists(filename)) File.Delete(filename);
using (var fileIn = new FileStream(filename, FileMode.Create))
{
var ser = new XmlSerializer(typeof(T));
ser.Serialize(fileIn, data);
}
}
public T FromXml(string filename)
{
using (var fs = new FileStream(filename, FileMode.Open))
{
var ser = new XmlSerializer(typeof(T));
return (T)ser.Deserialize(fs);
}
}
}
[Serializable]
public class Movie : BaseEntity
{
public string Title { get; set; }
public ushort Year { get; set; }
public double Rating { get; set; }
public string Director { get; set; }
public Movie() { }
public Movie(string title, ushort year, double rating, string director)
{
Title = title;
Year = year;
Rating = rating;
Director = director;
}
public override string ToString()
{
return string.Format("Title: {0}, year: {1}, rating: {2}, director: {3}", Title, Year, Rating, Director);
}