Why can't classes marked with Serializable be serializable using BinaryFormatter?

As we all know and mention on the MSDN website:

The serialization architecture provided by the .NET Framework handles object graphs and circular references correctly. The only requirement placed on object graphs is that all objects reference to the object that is being serialized should also be marked as Serializable . If this is not done, an exception will be thrown when the serializer tries to serialize the unmarked object.

My question is why does this restriction apply? (If this is a limitation !; -))

+4
source share
2 answers

BinaryFormatter has very unusual powers, nothing else looks like what it does. It can create an object of your class without starting its constructor. And this can give meaning to your properties without using access methods to property settings.

Otherwise, there is nothing special about this, it simply saves the field values โ€‹โ€‹of your class object. And restores them when the object is deserialized.

, - , , . , , , , . IsAdministrator. Control.Handle, .

, BinaryFormatter . , , . , - , , , . , , [Serializable].

+6

, fooobar.com/questions/348691/... , -

",

. , , BinaryFormatter, , , BinaryFormatter.

MSDN -

.

( , ), BinaryFormatter, SerializableAttribute , .

+2

Source: https://habr.com/ru/post/1625709/


All Articles