0

I am trying to Deserialize an XML object

however I get an error while tried to deserialize "There was an error reflecting field 'Tabels'

I am looking at object Tabels but I could not found the problem

attaching code and XML:

XML:

<?xml version="1.0" encoding="utf-8" ?>
<DPR>

<TLV type_Description="Passive Motion" type_Value ="01"  workPer="Table" table_name="Detection Event" />

 <TLV type_Description="Passive Occupation" type_Value ="03"  workPer="Table"   table_name="Detection Event" />

 <TLV type_Description="Active Barrier" type_Value ="04"  workPer="Table"   table_name="Detection Event" />

  <TLV type_Description="Glass Break" type_Value ="06"  workPer="Table"  table_name="Detection Event" />


 <Tabels>
 <Tabel Name="Detection Event" Length="1">
  <val_byte Num="0" byte_type="enum" byte_Value="00"   value_description="Close" />
  <val_byte Num="0" byte_type="enum" byte_Value="01" value_description="Open"     />
    <val_byte Num="0" byte_type="enum" byte_Value="02" value_description="Violated" />
  <val_byte Num="0" byte_type="enum" byte_Value="03" value_description="Gross Attack" />
  <val_byte Num="0" byte_type="enum" byte_Value="04" value_description="Low Integration" />
</Tabel>

</Tabels>

</DPR>

C# code:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Xml;
 using System.Xml.Serialization;

  namespace FFDProtocol
  {
  [XmlRoot("DPR")]
  public class TLVStructure
 {

    [XmlArray("TLV")]
    public List<TLV> LTLV;


    [XmlArray("Tabels")]
    public List<Tables> Tabels;


    public TLVStructure()
    {
        LTLV = new List<TLV> ();
        Tabels = new List<Tables>();
    }


    public class TLV         
    {
        [XmlAttribute("type_Description")]
        public string type_Description;
        [XmlAttribute("type_Value")]
        public string type_Value;

        [XmlAttribute("Length")]
        public string Length;


        [XmlAttribute("workPer")]
        public string workPer;

        [XmlElement("val_byte")]
        public List< val_byte> Val_byte;

        [XmlAttribute("table_name")]
        public string table_name;



        public TLV()
        {
            type_Description="";
            type_Value = "";
            Val_byte = new List<val_byte>();
            workPer = "";
            table_name = "";

        }

       public class val_byte 
        {


            [XmlAttribute("Num")]
            public string byteNum;
            [XmlAttribute("byte_Value")]
            public string byte_Value;
            [XmlAttribute("value_description")]
            public string value_description;            
            [XmlAttribute("byte_type")]
            public string byte_type;              
            [XmlAttribute("MCode")]


            public string MCode;
            public val_byte()
            {
                byteNum = "";
                byte_Value = "";
                value_description = "";
                byte_type = "";
                MCode = "";
            }
        }            

     }

    public class Tables
    {
        [XmlArray("Tabel")]
        public List<Tabel> LTabel;

        public Tables()
        {

            LTabel = new List<Tabel>();

        }

        public class Tabel
        {
            [XmlAttribute("Length")]
            public string Length;


            [XmlAttribute("Name")]
            public string Name;

            [XmlElement("val_byte")]
            public List<val_byte> LvalBytes;

            public Tabel()
            {
                Name = "";
                Length = "";
                LvalBytes = new List<val_byte>();
            }


            public class val_byte
            {


                [XmlAttribute("Num")]
                public string byteNum;
                [XmlAttribute("byte_Value")]
                public string byte_Value;
                [XmlAttribute("value_description")]
                public string value_description;
                [XmlAttribute("byte_type")]
                public string byte_type;
                [XmlAttribute("MCode")]


                public string MCode;
                public val_byte()
                {
                    byteNum = "";
                    byte_Value = "";
                    value_description = "";
                    byte_type = "";
                    MCode = "";
                }
            }
         }

     }
    }
  }
0

1 Answer 1

3

Tabels property of class TLVStructure should be List<Table> instead of List<Tables>. So if you replace following line

[XmlArray("Tabels")]
public List<Tables> Tabels;

with

[XmlArray("Tabels")]
public List<Table> Tabels;

It should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.