At the input there is a string that needs to be converted to an object. Do so

byte[] file = System.Text.Encoding.UTF8.GetBytes(sign); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); MemoryStream ms = new MemoryStream(file); ms.Position = 0; object obj = bf.Deserialize(ms); 

I get an error

Invalid binary input format. Start of content (in bytes):

If I save to file

 File(System.Text.Encoding.UTF8.GetBytes(sign), "application/text", name) 

then I get a file that is being tested without errors.

  • And if you do something like that? 'var tn = new TreeNode (); var node1 = tn.Nodes.Add ("123"); node1.Nodes.Add ("123"); node1.Nodes.Add ("123"); node1.Nodes.Add ("123"); node1.Nodes.Add ("123"); using (var fs = File.Create ("test.bin")) {new BinaryFormatter (). Serialize (fs, tn); fs.Flush (); } using (var fs = File.Open ("test.bin", FileMode.Open)) {var node = (TreeNode) new BinaryFormatter (). Deserialize (fs); treeView1.Nodes.Add (node); } ' - QuaternioNoir
  • I did not understand how to insert the code into the comment. - QuaternioNoir
  • one
    @QuaternioNoir What is TreeNode? - Pavel Mayorov
  • 2
    @QuaternioNoir large chunks of code in the comments are not appropriate, but small enough to wrap in "` "- those that are on the same key with a tilde - Bulson
  • 2
    @ e1s, Why are you doing this? Of course, what you wrote will not work, because you are trying to understand that it is not clear that it is not clear to deserialize something. Take the serialization of BinaryFormatter'ом , and then calmly deserialize. - Anton Komyshan

0