簡単なテストケースを次に示します。
[Serializable]
class Base
{
}
[Serializable]
class Derived : Base
{
}
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, new Derived());
ここでは特別なことは何もありません。「Serializable」タグのいずれかを削除するBinaryFormatter
と、アイテムがシリアル化できないため、怒鳴られます。理論的には、DataTable
DataTable の基本クラス - 'MarshalByValueComponent- isn't marked as serializeable either ('typeof(MarshalByValueComponent).IsSerializable
が 'false' を返すため、シリアル化も機能しないはずです。では、なぜ BinaryFormatter はこれを無視し、他のシリアル化できない型は無視しないのでしょうか? (または、そもそもMarshalByValueComponent
シリアル化可能としてマークされていないのはなぜですか?)