2

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.

leo-boy
  • 77
  • 3
  • 8
  • Where are you serializing? You are only constructing the serializer and not actually serializing any data. See my posting from yesterday : https://stackoverflow.com/questions/56906910/how-do-i-generate-a-soap-compatible-xml-response-with-correct-namespace-prefixes/56922262#comment100459651_56922262 – jdweng Jul 10 '19 at 12:23

0 Answers0