Person person = new Person(); 
person.Name = "something";

MemoryStream memorystream = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(memorystream, person);

use Base 64 (e.g. Convert.ToBase64String and Convert.FromBase64String).
Do not use Encoding.UTF8.GetString or anything similar - your binary data is not encoded text data, and shouldn't be treated as such.

MemoryStream memoryStream = new MemoryStream(); 
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, Person);
memoryStream.Position = 0;
string value = Convert.ToBase64String(memoryStream.ToArray());

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext