I am working on my own remote desktop C# program. I wondered if I could Serialize using BinaryFormatter an object of my own for example \"Packet\" that contains properties of B
BinaryFormatter is not a good choice for serialization over the network or to persistent storage, it is designed for serialization when you are communicating within the same machine. It is extremely intolerant of version differences of any assembly referenced in your serialized object on opposite ends of the connection, I personally have had a windows updates not being applied on one machine to cause the two sides to not be able to communicate.
Instead use a serializer more designed for network communication like DataContractSerializer or a 3rd party binary serializer like ProtoBuf-net.
This is possible, but I discourage it. The BinaryFormatter
algorithm is proprietary, so it will be very difficult to write non-.NET applications using such data. The format has changed in the past, and may change in the future, so it is unsafe to use it for persistent data you expect to open again in the future with a new .NET version. I think BinaryFormatter
was originally designed for passing data between processes on one machine, not for persisting data.
BinaryFormatter
is inefficient for data that contains multiple properties because it requires deserializing the entire object to access any field. This is especially problematic if the data contains large data like images.
If your data does not require random access, I suggest serializing it to a text format like JSON or XML. If the data is large, you should consider compressing the text-encoded data.
If you require random-access to data you should investigate data stores like MySQL or SQLite.