[Mono-list] Serialization bug

Yury Serdyuk Yury at serdyuk.botik.ru
Mon Jul 2 06:45:08 UTC 2012


Hi !

I have a simple program that works good under Microsoft .NET, but 
doesn't work under Mono on Linux:

using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

    [Serializable]
    public struct Complex {
        public double Re;
        public double Im;

        public Complex(double re, double im) {
            Re = re;
            Im = im;
        }

        public static Complex operator + (Complex x, Complex y)
        {
            return new Complex(x.Re + y.Re, x.Im + y.Im);
        }
    }


    public class Geometry {

     public static void Main ( String[] ars )  {

            const int dim = 100;
            Complex[][] A = new Complex[dim][];
            for (int i = 0; i < dim; i++) {
                A[i] = new Complex[dim];
            }

            MemoryStream ms = new MemoryStream ( 16384 );
            new BinaryFormatter().Serialize ( ms, A );            

     }
    }

Trying to run it, I have got:

$ mono Geometry.exe

Unhandled Exception: System.NullReferenceException: Object reference not 
set to an instance of an object
  at 
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.GetAssemblyNameId 
(System.String assembly) [0x00000] in <filename unknown>:0
  at 
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.GetAssemblyId 
(System.Reflection.Assembly assembly) [0x00000] in <filename unknown>:0
  at 
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteTypeSpec 
(System.IO.BinaryWriter writer, System.Type type) [0x00000] in <filename 
unknown>:0
  at 
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteGenericArray 
(System.IO.BinaryWriter writer, Int64 id, System.Array array) [0x00000] 
in <filename unknown>:0
  at 
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray 
(System.IO.BinaryWriter writer, Int64 id, System.Array array) [0x00000] 
in <filename unknown>:0
  at 
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectInstance 
(System.IO.BinaryWriter writer, System.Object obj, Boolean 
isValueObject) [0x00000] in <filename unknown>:0
  at 
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteQueuedObjects 
(System.IO.BinaryWriter writer) [0x00000] in <filename unknown>:0
  at 
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectGraph 
(System.IO.BinaryWriter writer, System.Object obj, 
System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in 
<filename unknown>:0
  at 
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize 
(System.IO.Stream serializationStream, System.Object graph, 
System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in 
<filename unknown>:0
  at 
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize 
(System.IO.Stream serializationStream, System.Object graph) [0x00000] in 
<filename unknown>:0
  at Geometry.Main (System.String[] ars) [0x00000] in <filename unknown>:0

I have tried Mono v.2.11.2.

Is it a bug in Mono and how to workaround it if possible ?

Thanks,
             Yury


More information about the Mono-list mailing list