C# – InvalidOperationException at XmlSerializer(typeof(List))

Hi folks.

Redditor ElMalakai told me about serialisation and I just loved it.

I googled around and sadly I'm unable to do it myself.

I want to create a xml file from a List<Employee> but the Serializer throws an InvalidOperationException. Google says that many people miss to make the class public, but he throws the exception even after it.

StracktraceEmployee.cs

 void SaveEmployeesToFile() { XmlSerializer serializer = new XmlSerializer(typeof(List<Employee>)); using (TextWriter writer = new StreamWriter(_XmlSavePath.FullName)) { serializer.Serialize(writer, _employees); } } 

I would be really thunkful if you guys could help me.

Thanks 🙂

EDIT: The Stacktrace says that he cant serialize Employee becaue no parameters is available. (badly translated)

by Jonas_Dralle via /r/csharp

Leave a Reply