I have an error about serialization of complex numbers in MONO. If I run the same code in a Microsoft .NET environment I have no error at all.
I'm using a binary formatter, and this is the function using it:
public static void dump_to_file(List<QuantumOperator> obj, string custom_filename = "")
{
if (custom_filename.Length > 0)
{
custom_filename = "-" + custom_filename;
}
var filename = filename_prefix + "-" + filename_suffix + custom_filename + ".pickle";
Console.WriteLine("Begin writing file: " + filename);
var binform = new BinaryFormatter();
var f = new FileStream(filename, FileMode.OpenOrCreate);
var sw = Stopwatch.StartNew();
binform.Serialize(f, obj);
f.Close();
sw.Stop();
Console.WriteLine("Writing time: " + sw.Elapsed.TotalSeconds.ToString() + " seconds.");
Console.WriteLine("Write done. Closing file.");
}
I have this error running with MONO (under linux with "mono-sgen"):
Unhandled Exception: System.Runtime.Serialization.SerializationException: Type System.Numerics.Complex is not marked as Serializable. at System.Runtime.Serialization.Formatters.Binary.BinaryCommon.CheckSerializable (System.Type type, ISurrogateSelector selector, StreamingContext context) [0x00000] in :0 at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.GetObjectData (System.Object obj, System.Runtime.Serialization.Formatters.Binary.TypeMetadata& metadata, System.Object& data) [0x00000] in :0
but if I compile it with Visual Studio (2013) I have no problem at all, as I said.
I'm not a C# expert, I'm started to code two weeks ago, so I have no idea how to fix this problem. I tried to create a custom Complex class (marked as serializable) derived from system.numerics.complex, but .NET is no happy with this solution, because system.numerics.complex is a sealed class.
thanks in advance, Fausto