[ Foro de C# ]

tengo un error al querer acceder a los valores de una clase

12-Jun-2019 23:39
Invitado (Esperanza )
0 Respuestas

tengo este codigo
public void mostrarXml(object sender, EventArgs e)
       {
           try
           {
               XmlDocument doc = new XmlDocument();
               string xml = btnCargarXml.FileName;            
                XmlSerializer serializer = new XmlSerializer(typeof(Comprobante));
               FileStream fs = new FileStream(@"C:\Users\ehernandezm\Downloads\" + xml, FileMode.Open);
               Comprobante ds = (Comprobante)serializer.Deserialize(fs);
               txtFolioInter.Text = ds.Folio;
               txtProv.Text = ds.Temisor.Nombre; // aqui es donde me manda el error, "Referencia a objeto no establecida como instancia de un objeto."
               // txtRfc.Text = ds.Temisor.Rfc;
               txtfechaEmision.Text = ds.Fecha;
               txtMetdPago.Text = ds.MetodoPago;
               // txtUsoCFDI.Text = ds.TReceptor.UsoCFDI;
               txtFormPago.Text = ds.FormaPago;
               // txtFolioFis.Text = ds.UUID.UUID;
               txtSubtotal.Text = ds.SubTotal;
               // txtIVA.Text = ds.TImpuestos.TotalImpuestosTrasladados;
               txtTotal.Text = ds.Total;
               fs.Close();
           }
           catch (Exception ex)
           {
               var Error = ex.Message;
               txtruta.Text = Error;
           }          
       }
esta es mi clase
   [XmlRootAttribute(Namespace = "http://www.sat.gob.mx/cfd/3")]
   public partial class Comprobante {
     [XmlAttributeAttribute()]
     public string Folio { get; set; }
     [XmlAttributeAttribute()]
     public string Fecha { get; set; }
     [XmlAttributeAttribute()]
     public string FormaPago { get; set; }
     [XmlAttributeAttribute()]
     public string SubTotal { get; set; }
     [XmlAttributeAttribute()]
     public string Total { get; set; }
     [XmlAttributeAttribute()]
     public string MetodoPago { get; set; }
   
     [XmlElementAttribute()]
     public Temisor Temisor;
     [XmlElementAttribute()]
     public TReceptor TReceptor;
     [XmlElementAttribute()]
     public TConcepto TConcepto;
     [XmlElementAttribute()]
     public TImpuestos TImpuestos;
     [XmlElementAttribute()]
     public TComplemento UUID;
   }
   public partial class Temisor {
      [XmlAttributeAttribute()]
      public string Nombre {get; set; }
      [XmlAttributeAttribute()]
      public string Rfc { get; set; }
   }
   public partial class TReceptor {    
      [XmlAttributeAttribute()]
      public string UsoCFDI { get; set; }
   }    
   public partial class TConcepto
   {
       [XmlAttributeAttribute()]
       public string Cantidad { get; set; }
       [XmlAttributeAttribute()]
       public string Descripcion { get; set; }
       [XmlAttributeAttribute()]
       public string ValorUnitario { get; set; }
       [XmlAttributeAttribute()]
       public string Importe { get; set; }
   }
   public partial class TImpuestos {
       [XmlElementAttribute()]
        public string TotalImpuestosTrasladados { get; set; }    
   }
   public partial class TComplemento{
       [XmlElementAttribute()]
       public string UUID { get; set; }
   }


el xml que quiero deserializar es un cfdi 3.3
ayuda por favor




(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)