Erik Kerber
Erik Kerber

Reputation: 5656

IsSerializable returning "false" for an object marked Serializable

I'm attempting to serialize a DenseMatrix object which is an object provided within the MathNET Numerics project.

DenseMatrix.cs

Below I have provided some useful information.

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

Answers (1)

Erik Kerber
Erik Kerber

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

Related Questions