0
using System.Xml.Serialization;

namespace Program
{
    internal class Program
    {
        internal static void Main()
        {
            string xml =
            @"<row>
                <AI></AI>
            </row>
            ";

            XmlSerializer serializer = new XmlSerializer(typeof(row));
            using (StringReader reader = new StringReader(xml))
            {
                row book = (row)(serializer.Deserialize(reader));
            }
        }
    }

    [Serializable]
    public class row
    {
        [XmlElement(IsNullable = true)]
        public int? AI;
    }
}

It just does not work:

System.InvalidOperationException: 'There is an error in XML document (3, 15).'

If I feed xml to XDocument and try to serialize this document instead it does not work either.

StackOverflow compels me to write more letters about the issue, I don't know what else to say, I feel very sad and overwhelmed.

Markus
  • 20,838
  • 4
  • 31
  • 55
Nick Farsi
  • 366
  • 4
  • 19
  • Well I was really hoping for something more direct – Nick Farsi Jun 28 '22 at 14:37
  • 1
    The problem is that `` is not null, it's an empty string, which is not the same thing – Charlieface Jun 28 '22 at 16:19
  • @NickFarsi - Unfortunately there is nothing more direct. Microsoft serializers are less customizable than say Json.NET. Only other option I can imagine is to preprocess the XML with an xslt transform or via LINQ to XML. – dbc Jun 28 '22 at 18:39

0 Answers0