Save file - xmlSerializer
Your error is in new XmlSerializer(typeof(type));
. You don't need typeof
. new XmlSerializer(type);
is enough.
Since you serialize file
object (and its type can be determined in the function) you don't have to pass its type. So your code can be re-written as
public void Save<T>(T file, String path)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (StreamWriter writer = new StreamWriter(path))
{
serializer.Serialize(writer, file);
}
}