The above code supplied is missing a couple of classes so I can't fully check where the error may be or what type of error that you are encountering. However, I used my own converter code and everything converted without an error.
Here is what I used:
public static class XmlConverter
{
public static string FromClass<T>(T data)
{
string response = string.Empty;
var ms = new MemoryStream();
try
{
ms = FromClassToStream(data);
if (ms != null)
{
ms.Position = 0;
using (var sr = new StreamReader(ms))
response = sr.ReadToEnd();
}
}
finally
{
ms.Flush();
ms.Dispose();
ms = null;
}
return response;
}
public static MemoryStream FromClassToStream<T>(T data, XmlSerializerNamespaces ns = null)
{
var stream = default(MemoryStream);
if (data != null)
{
var settings = new XmlWriterSettings()
{
Encoding = Encoding.UTF8,
Indent = true,
ConformanceLevel = ConformanceLevel.Auto,
CheckCharacters = true,
OmitXmlDeclaration = false
};
try
{
XmlSerializer serializer = XmlSerializerFactoryNoThrow.Create(typeof(T));
stream = new MemoryStream();
using (XmlWriter writer = XmlWriter.Create(stream, settings))
{
serializer.Serialize(writer, data, ns);
writer.Flush();
}
stream.Position = 0;
}
catch (Exception)
{
stream = default(MemoryStream);
}
}
return stream;
}
public static T ToClass<T>(string data)
{
var response = default(T);
if (!string.IsNullOrEmpty(data))
{
var settings = new XmlReaderSettings()
{
IgnoreWhitespace = true,
DtdProcessing = DtdProcessing.Ignore
};
XmlSerializer serializer = XmlSerializerFactoryNoThrow.Create(typeof(T));
using (var sr = new StringReader(data))
using (var reader = XmlReader.Create(sr, settings))
response = (T)Convert.ChangeType(serializer.Deserialize(reader), typeof(T));
}
return response;
}
}
public static class XmlSerializerFactoryNoThrow
{
public static Dictionary<Type, XmlSerializer> cache = new Dictionary<Type, XmlSerializer>();
private static readonly object SyncRootCache = new object();
public static XmlSerializer Create(Type type)
{
XmlSerializer serializer;
lock (SyncRootCache)
if (cache.TryGetValue(type, out serializer))
return serializer;
lock (type)
{
serializer = XmlSerializer.FromTypes(new[] { type })[0];
}
lock (SyncRootCache) cache[type] = serializer;
return serializer;
}
}
And here is how to use it:
var data = new FeePlanGenerate();
var xmlString = XmlConverter.FromClass(data);
UPDATE I just re-read your question title and saw that the problem was in fact with the List properties in the class provided.
The answer is dependant on how the XML data is formatted. My guess is that the nodes are one beneath the other but without seeing the raw XML that you want to deserialize it is difficult to say.
My best guess would be to do the following:
public class FeePlanGenerate
{
[XmlElement]
public List<FeePlan> FeePlanList { get; set; }
[XmlElement]
public List<FeeComponent> FeeComponentList { get; set; }
public string StudentName { get; set;}
public string StudentAddress { get; set; }
public string CurriculumName { get; set; }
public string CourseName { get; set; }
public string BCNumber { get; set; }
public DateTime? AddmissionDate { get; set; }
public string AddmissionOfficer{ get; set; }
public string Contant1 { get; set; }
public string Contant2 { get; set; }
public string AdmissionCode { get; set; }
public decimal? TotalInvoiceAmount { get; set; }
public decimal? TotalPayableFee { get; set; }
public string ArrayOfFeePlanGenerate { get; set; }
}