[Mono-list] OnDeserialization problem

Chris Howie cdhowie at gmail.com
Tue Mar 17 14:11:06 EDT 2009


On Thu, Feb 26, 2009 at 5:44 PM, Dave Null <eric.jacoboni at gmail.com> wrote:
> I'm trying to use the IDeserializationCallback interface with Mono 2.2  on
> OS X 1.5.6 :
>
> [snip]
>
>       [NonSerialized] private int[] tab;
>       public virtual void OnDeserialization(Object sender) {
>          for (int i = 0; i < limite; i++) {
>            tab[i] = i + 42;
>          }
>        }
>
> [snip]
>
> This code compile fine with gmcs but execution throws an
> System.NullReferenceException :

NonSerialized members are initialized to the default value for that
type, which is null for reference types like arrays.  So you can't
assign anything to tab[i] until you create the array.  It looks like
you are missing "tab = new int[limite];".

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers


More information about the Mono-list mailing list