user192936
user192936

Reputation:

Serialize a ISerializable class without parameterless constructor

I am using a class which implements ISerializable but does not have a parameterless constructor. The class is from EmguCV library:

[Serializable]
public class DenseHistogram : UnmanagedObject, ISerializable, IEquatable<DenseHistogram>
{
    public DenseHistogram(int binSize, RangeF range);
    public DenseHistogram(int[] binSizes, RangeF[] ranges);
    public DenseHistogram(SerializationInfo info, StreamingContext context);
}

As you may guess I get a "Emgu.CV.DenseHistogram cannot be serialized because it does not have a parameterless constructor." exception. I know that -and why- I need the parameterless constructor but it kind of makes me confused since the class implements ISerializable.

Upvotes: 1

Views: 589

Answers (1)

dbc
dbc

Reputation: 116615

This is for binary serialization through the BinaryFormatter, not the more familiar serialization through XmlSerializer.

Some information here: Custom serialization. By default binary serialization serializes the fields of classes, ISerializable allows this to be overridden, for instance when serializing between different versions.

Upvotes: 1

Related Questions