0

I'am trying to create and download a XML from the database. I have this code in my controller

    public void ExportListToXML()
    {
        var data = db.correct.ToList();
        Response.ClearContent();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment; filename=itmyfile.xml"); Response.ContentType = "text/xml";
        var serializer = new
        System.Xml.Serialization.XmlSerializer(data.GetType()); serializer.Serialize(Response.OutputStream, data);
    }

And this code/link in my view

@Html.ActionLink("Export to XML", "ExportListToXML")

No errors in the code.

I can run the project without errors.

But I get the error message "System.InvalidOperationException was unhandled by user code" when I click the link. See screenshot.

Error message

Xtreme
  • 1,601
  • 7
  • 27
  • 59
  • You've not given a lot to go on, you need to provide enough code for someone to reproduce. Not only that, you've blanked out the useful part of the exception. That type is not serializable for whatever reason. – Charles Mager May 22 '15 at 09:22
  • 1
    possible duplicate of [XmlSerializer - There was an error reflecting type](http://stackoverflow.com/questions/60573/xmlserializer-there-was-an-error-reflecting-type) – Charles Mager May 22 '15 at 09:23
  • Unless you can share code that reproduces the problem, or at the minimum the full stack trace and exception message, we can only point you towards generic help, like https://msdn.microsoft.com/en-us/library/aa302290.aspx – dbc May 22 '15 at 15:25

0 Answers0