Error in Deserializing XML file

FaCToR.eXh

New Member
I'm trying to deserialize an XML and display a value from its element but I'm getting this error:
EgvVg.png
I just found some samples from the internet and tried to edit the code according to my need, but I believe I'm not doing it right. Please see below classes and sample XML data. Your comments and suggestions will be highly appreciated.MainForm\[code\]public partial class MainForm : Form{ public MainForm() { InitializeComponent(); } public FileInfo ItemFile { get { return new FileInfo(@"C:\Data_120702-015842_440.xml"); } } void MainFormLoad(object sender, EventArgs e) { if (ItemFile.Exists) { List<Record> lst = new List<Record>(); XmlSerializer xml = new XmlSerializer(lst.GetType()); using (Stream s = ItemFile.OpenRead()) { lst = xml.Deserialize(s) as List<Record>; } _items.Add(item); MessageBox.Show(lst[0].Material_Code); } }}\[/code\]Record\[code\]public class Record{ public string Material_Code; public string Sub_Brand_Code; public string Sub_Brand_Text; public string Pack_Size_Code; public string Pack_Size_Text; public string Pack_Type_Code; public string Pack_Type_Text; public Record() { } public Record(string Material_Code, string Sub_Brand_Code, string Sub_Brand_Text, string Pack_Size_Code, string Pack_Size_Text, string Pack_Type_Code, string Pack_Type_Text ) { this.Material_Code = Material_Code; this.Sub_Brand_Code = Sub_Brand_Code; this.Sub_Brand_Text = Sub_Brand_Text; this.Pack_Size_Code = Pack_Size_Code; this.Pack_Size_Text = Pack_Size_Text; this.Pack_Type_Code = Pack_Type_Code; this.Pack_Type_Text = Pack_Type_Text; }}\[/code\]XML Structure\[code\]<?xml version="1.0" encoding="UTF-8"?><MntProdHierAttrMDM> <Record> <Material_Code>60024517</Material_Code> <Sub_Brand_Code>SB000416</Sub_Brand_Code> <Sub_Brand_Text>Zwitsal</Sub_Brand_Text> <Pack_Size_Code>PS000224</Pack_Size_Code> <Pack_Size_Text>50ML</Pack_Size_Text> <Pack_Type_Code>PT000042</Pack_Type_Code> <Pack_Type_Text>BOTTLE</Pack_Type_Text> </Record></MntProdHierAttrMDM>\[/code\]
 
Back
Top