c# - how does binaryformatter serializes objects? -
binaryformer
is behaving strangely in my code. I have the following code
[serialable] Public class log entry {Private IIT; Private listing & lt; Object & gt; Data = new list & lt; Object & gt; (); Public IIT ID {return ID; }} Public IList & lt; Object & gt; Data {Receive {Return Data. ASRD ONLY (); }} ...} .... .... Private Static Read Only BinaryFormatter logSerializer = New BinaryFormatter (); .... .... Public Zero Serialism (ILIIT & lt; LogEntry & gt; Log Entries) {(MemoryStream Serialization Stream = New MemoryStream ()) {LogCentilizer. Serialize (serialization stream, log entries); This.binarySerializedLog = serializationStream.GetBuffer (); }}
In some machines (32 or 64 bit machines), it is sorted in binary format - which is expected. But in some machines (these are all 64 bit machines and not for debug builds) it is not serializing; showing binary serialized log
is showing ToString ()
all individual Data , the class name (
... log entry}
) and id
value. My question is - is there any specific reason for this kind of behavior or am I doing something wrong? thank you in advanced.
Your question is not very clear (can you define "no serial"?), But some thoughts:
To capture buffer you should actually use ToArray ()
, not GetBuffer ()
(which is cheap, but gives oversized array, and should only be used with length
.
Where are you looking for this . ToString ( )
? Type the object type, either the field ( Uses reflection to write [serializable]
), or uses the customer's serialization (for ISerializable
), it never calls Toastring ()
(unless your isiariasisable
). However, strings will be will in the output "as is".
Note that BinaryFormatter
can be brittle between versions, so be careful if you do this for any time Keeping the data (this is generally good for transportation, however, you consider updating both ends at the same time). If you already know that your .data is an object, there is a series of contract-based serialisers that can provide more consistency. If you think that it is worth investigating then I can provide more specific support.
Comments
Post a Comment