I have a list and I want to write it to a file but JsonSerializer.Serialize(mylist)throws an error
here is the code:
private void CheckIfFileExistsOrCreateOne()
{
if (!File.Exists(filePath))
{
LoginInfo secretary = new LoginInfo("secretary", "secretary", new Secretary_Form());
LoginInfo admin = new LoginInfo("admin", "admin", new Administrator_Form());
mylist.Add(secretary);
mylist.Add(admin);
File.WriteAllText(filePath, JsonSerializer.Serialize(mylist));
}
}
and the error:

File.WriteAllText...and inspect themyListobject. You should be able to see what is causing the error.