![]() |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace SimpleXMLSerialize
{
public class Employee
{
public int EID { get; set; }
public string EName { get; set; }
public string Designation { get; set; }
public long Phone { get; set; }
}
public class SXML
{
public static void Main(string[] args)
{
List Emplist = new List();
Employee emp1 = new Employee();
emp1.EID = 1;
emp1.EName = "Naveen";
emp1.Designation = "QA";
emp1.Phone = 9895356522;
Employee emp2 = new Employee();
emp2.EID = 2;
emp2.EName = "Balu";
emp2.Designation = "Software Developer";
emp2.Phone = 9232546554;
Emplist.Add(emp1);
Emplist.Add(emp2);
Serialize(Emplist);==============>> ERROR
}
public void Serialize(List list)
{
XmlSerializer xmlser = new XmlSerializer(typeof(List< Employee>));
using (StreamWriter stmw = new StreamWriter(@"D:\sxml.xml"))
{
xmlser.Serialize(stmw, list);
}
}
}
I tried for SERIALIZE buit I got error in this line )serialize(emplist)
Error Shows:object reference is required for non static fileds,method or property
Error Shows:object reference is required for non static fileds,method or property
}

Iftikar HussainPosted Jul 22, 2013, 5:22 AM
Regards,
Iftikar
om prakashPosted Jul 22, 2013, 5:19 AM
I created the class file also but I got the error which I have highlited in block letters
Iftikar HussainPosted Jul 22, 2013, 5:05 AM
Try like this
Regards,
Iftikar
om prakashPosted Jul 22, 2013, 5:03 AM
Serialize(Emplist);==============>> ERROR
Error Shows: object reference is required for non static fileds,method or property