Bug 5935 - Serialization bug
Summary: Serialization bug
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
Depends on:
Reported: 2012-06-30 04:41 UTC by YurySerdyuk
Modified: 2012-09-18 15:23 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description YurySerdyuk 2012-06-30 04:41:53 UTC
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;

    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

My Mono version is:
$ mono -V
Mono JIT compiler version 2.11.2 (tarball Sat Jun 30 02:19:45 MSK 2012)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)

Is it possible to workaround this bug as interim solution ?

Comment 1 YurySerdyuk 2012-07-03 01:37:21 UTC
I have found a place where the exception is occured -
it is ObjectWriter module, WriteTypeSpec function:

> case TypeTag.GenericType:
>                     writer.Write (type.FullName);
>                     writer.Write ((int)GetAssemblyId (type.Assembly));
>                     break;

Here, GetAssemblyId returns null because the assembly was not
registered early in
Hashtable _assemblyCache
Comment 2 Martin Baulig 2012-09-18 15:23:16 UTC
Fixed; master ab016b5.