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.<WriteBufferedResponseContentAsync>d__1b.MoveNext()</StackTrace><InnerException><Message>An error has occurred.</Message><ExceptionMessage>The type System.Collections.Generic.List
1[[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; }
}