0
     FileStream fs = new FileStream("Answears.dat", FileMode.Create);
     Dictionary<string, List<string>> chats = new Dictionary<string, List<string>>();

     BinaryFormatter formatter = new BinaryFormatter();
     public void Start()
    {

                chats = (Dictionary<string, List<String>>) formatter.Deserialize(fs); //here is a error 
                fs.Close();

    }

do you now any other option to save the dictionary(and also later load again) in a file. ^^

thanks for you help

Paul :)

  • 2
    See [BinaryFormatter alternative](http://stackoverflow.com/q/3512776/3744182) or [C# - Human readable serialization alternatives to BinaryFormatter](http://stackoverflow.com/q/33265104/3744182). Related: [What are the deficiencies of the built-in BinaryFormatter based .Net serialization?](http://stackoverflow.com/q/703073/3744182). – dbc Dec 31 '16 at 21:10

1 Answers1

2

I would use Json.Net, independent from assembly version changes and results in a readable text...

File.WriteAllText(filename, JsonConvert.SerializeObject(yourDict));

Later, you can load it as

var yourDict = JsonConvert.DeserializeObject<Dictionary<string,List<string>>>(File.ReadAllText(filename));
L.B
  • 114,136
  • 19
  • 178
  • 224