MSJ
MSJ

Reputation: 423

Class with [Serializable] attribute refuse to serialize

I have class decorated with [Serializable] attribute. I am creating object of that class and adding to datatable. When I serialize datatable using BinarySerializer I am getting error as

Type does not implement IXmlSerializable interface therefore can not proceed with serialization.

Here is the sample code

[Serializable]
class PropertyData
{
  // Properties
}

class Main
{
  PropertyData obj = new PropertyData();

  dttable.Rows.Add(val1,val2,val3, obj);

  // ...

  ObjbinaryFormatter.Serialize(stream, dttable); // throws exception

}

Please suggest the solution.

Upvotes: 0

Views: 557

Answers (1)

Ricardo Peres
Ricardo Peres

Reputation: 14555

BinaryFormatter expects the [Serializable] attribute alright, but the exception does not seem to come from BinaryFormatter, but from XmlSerializer. The problem seems to be that the class is not public. However, your code is not clear, as you seem to be serializing a DataTable. Try to store your DataTable inside a DataSet and instead serialize that.

For a quick reference, please checkout .NET Serializers

Upvotes: 1

Related Questions