I am working on project which needs to get xml file of a table in our database. As I am working on asp.net core on backend, I need to query on database and serialize to xml and return response. As per my Code below I got the following errors.
[HttpGet, Route("GetXml")]
public ActionResult<GenericResponse> GenerateXml()
{
var cellData = _repoWrapper.Purchase.FindByCondition(a => a.IsDeleted == false);
//since servicestack we used in text also have xml serializer so it is necessary to use system.xml .serializer method
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(cellData.GetType());
String s= x.ToString();
return _response;
}
For this code I got error like: System.InvalidOperationException: 'To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable'
And Again, doing this:
[HttpGet, Route("GetXml")]
public ActionResult<GenericResponse> GenerateXml()
{
var cellData = _repoWrapper.Purchase.FindByCondition(a => a.IsDeleted == false).ToList();
//since servicestack we used in text also have xml serializer so it is necessary to use system.xml .serializer method
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(cellData.GetType());
String s= x.ToString();
return _response;
}
I got error like: System.InvalidOperationException: 'There was an error reflecting type 'System.Collections.Generic.List' and: InvalidOperationException: Cannot serialize member 'Total' of type System.Nullable'1[System.Double]. XmlAttribute/XmlText cannot be used to encode complex types.