XmlSerializer: The string '' is not a valid AllXsd value

前端 未结 5 1571
独厮守ぢ
独厮守ぢ 2020-12-20 10:52

I\'m getting this message,\"The string \'7/22/2006 12:00:00 AM\' is not a valid AllXsd value.\", when deserializing an XML, the element contains a date, this is the property

5条回答
  •  眼角桃花
    2020-12-20 11:31

    For those who come across this here is the simplest answer, I ran into the same issue, but didn't need nullable DateTime. The XMLElement only need a get not a set when rendering XML.

    private DateTime _fechaInicioRelacion;
    
    [XmlElement("FEC_INICIO_REL")]
    public string FechaInicioRelacionString
    {
        get
            {
                return _fechaInicioRelacion.ToString("yyyy-MM-ddTHH:mm:ss");
            }
        set { }
    }
    
    [XmlIgnore]
    public DateTime FechaInicioRelacion
    {
        get { return _fechaInicioRelacion; }
        set { _fechaInicioRelacion = value; }
    }
    

提交回复
热议问题