收到以下错误。似乎其他线程可能有很多可能的原因。我使我的代码尽可能简单。
There is an error in XML document (2, 2).
public class MovieSummary
{
public List<Movie> Movies { get; set; }
}
public class Movie
{
public int id { get; set; }
public string name { get; set; }
}
public static MovieSummary Deserialize()
{
using (TextReader reader = new StreamReader("c:\\movies.xml"))
{
XmlSerializer serializer = new XmlSerializer(typeof(MovieSummary));
return (MovieSummary)serializer.Deserialize(reader);
}
}
public ActionResult GetListOfMovies()
{
MovieSummary summary = Deserialize();
return View(summary);
}
<?xml version="1.0" ?>
<movies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<movie>
<id>1</id>
<name>The Dark Knight</name>
</movie>
</movies>