0

the old question solved to json side I get normal response from API when I request content type 'text/json and the problem when I request content type 'text/xml; I get this message An error has occurred.The 'ObjectContent1' type failed to serialize the response body for content type 'text/xml; charset=utf-8'.</ExceptionMessage><ExceptionType>System.InvalidOperationException</ExceptionType><StackTrace /><InnerException><Message>An error has occurred.</Message><ExceptionMessage>There was an error generating the XML document.</ExceptionMessage><ExceptionType>System.InvalidOperationException</ExceptionType><StackTrace> at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content) at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.WebHost.HttpControllerHandler.&lt;WriteBufferedResponseContentAsync&gt;d__1b.MoveNext()</StackTrace><InnerException><Message>An error has occurred.</Message><ExceptionMessage>The type System.Collections.Generic.List1[[testtransotels.data.cities, testtransotels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] may not be used in this context.System.InvalidOperationException at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterObject.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterObject.Write2_anyType(Object o)

my code as you see

   private datacontext db = new datacontext();
 public object Post([FromBody]Request Request)
    {
        return db.Student;

    }
 public class Student
{
    [DataMember]

    public string StudentID { get; set; }

    [DataMember]

    public string StudentName { get; set; }
    [DataMember]

    public string StudentCode { get; set; }
}
yhyasoft
  • 1
  • 1
  • 1
    Please see the answer here http://stackoverflow.com/questions/12641386/failed-to-serialize-the-response-in-web-api – Mike Aug 24 '16 at 17:55
  • This was answered previously. Check http://stackoverflow.com/questions/12641386/failed-to-serialize-the-response-in-web-api – Mike Aug 24 '16 at 17:59
  • the answer for json and didn't help me for xml – yhyasoft Aug 24 '16 at 18:02

0 Answers0