Reputation: 5656
I'm attempting to serialize a DenseMatrix object which is an object provided within the MathNET Numerics project.
Below I have provided some useful information.
I can see from both the object explorer as well as .NET reflector that this class (and everything this class inherits from) is marked as [Serializable].
Attribute.IsDefined(typeof(MathNet.Numerics.LinearAlgebra.Double.DenseMatrix), typeof(SerializedAttribute)) returns true.
typeof(MathNet.Numerics.LinearAlgebra.Double.DenseMatrix).IsSerializable returns false
It seems everything in the Mathnet.Numerics Matrix family is marked [Serializable], though they all show the same non-serializable behavior.
Now, when I attempt to run my object through a BinaryFormatter, I get a SerializationException "Type MathNet.Numerics.LinearAlgebra.Double.DenseMatrix is not marked as Serializable".
What is going on here? I know that the BinaryFormatter is looking directly at the IsSerializable property, so that's why it's coughing up. So why is IsSerializable returning false?
EDIT
The question is directed more toward the .NET implementation of IsSerializable in general, and only uses The Mathnet example as context.
2nd EDIT
I think adding to the confusion was the fact that I was using MathNet's "portable" library version. In order to make the portable library compile, they had created a custom SerializableAttribute that would be used since System.SerializableAttribute is not available for a portable library. When running with Mono, System.Type would look for System.SerializableAttribute, but only find MathNet.SerializableAttribute.
Upvotes: 3
Views: 2161
Reputation: 5656
.NET recursively checks all members of objects marked [Serializable], and IsSerializable returns false if the types of any members of a [Serializable] class are not marked [Serializable] as well.
The solution to the above case is to simply mark the classes that are members in DenseMatrix as [Serializable].
i.e. DenseColumnMatrixStorage
MatrixStorage
Upvotes: 1