1

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:

enter image description here

2
  • 1
    Can you show LoginInfo class declaration? Commented Dec 24, 2020 at 15:37
  • Add a breakpoint at the line File.WriteAllText... and inspect the myList object. You should be able to see what is causing the error. Commented Dec 24, 2020 at 15:45

1 Answer 1

1

It seems like you can't pass a form to a list and write it to a file because it's too large so I changed my strategy and I used string to variable name to approach what I wanted.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.