i need to backup a list filled with objects of this class:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XML2
{
public enum userLevel { Manager, Librarian, Reader };
[Serializable]
public class Users
{
public string _username { get; set; }
public string _password { get; set; }
public userLevel _level { get; set; }
public Users()
{
}
public Users(string name, string password, userLevel level)
{
_username = name;
_password = password;
_level = level;
}
}
}
This is my list class:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace XML2
{
[Serializable]
public class userDB
{
List<Users> users = new List<Users>();
public userDB()
{
users.Add(new Users("Administrator", "12345678", userLevel.Manager));
users.Add(new Users("Librarian", "12345678", userLevel.Librarian));
users.Add(new Users("Reader", "12345678", userLevel.Reader));
save();
}
public void save()
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Users>));
using (FileStream fs = File.Open(@"users.xml", FileMode.Create))
{
serializer.Serialize(fs, users);
}
}
}
}
When i execute it without the Enum it works fine but with it it crashes.
is there any solution for this?
When i debug the program it says:
"InvalidOperationException was unhandled"
'There was an error reflecting type 'System.Collections.Generic.List' 1[Library.Users]".
and it points on this line:
Code:
XmlSerializer serializer = new XmlSerializer(typeof(List<Users>));
Bookmarks