[Mono-dev] ArgumentNullException in GetSerializationCallbacks method
Vadim B. Guzev
vguzev at yandex.ru
Mon Feb 12 12:33:31 EST 2007
Hello,
>From time to time I'm getting a very strange exception when I'm trying to deserialize different objects:
--8<----------------------------------------------
Error type: System.ArgumentNullException
Error message: null key
Parameter name: key
Error source: mscorlib
Error stack trace:
at System.Collections.Hashtable.get_Item (System.Object key) [0x00000]
at System.Runtime.Serialization.SerializationCallbacks.GetSerializationCallbacks (System.Type t) [0x00000]
at System.Runtime.Serialization.ObjectManager.RaiseOnDeserializingEvent (System.Object obj) [0x00000]
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectContent (System.IO.BinaryReader reader, System.Runtime.Serialization.Formatters.Bin
ary.TypeMetadata metadata, Int64 objectId, System.Object& objectInstance, System.Runtime.Serialization.SerializationInfo& info) [0x00000]
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectInstance (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean hasTypeIn
fo, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000]
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, System.Int64& objectId, Sys
tem.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000]
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) [0x00000]
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, S
ystem.Runtime.Remoting.Messaging.Header[]& headers) [0x00000]
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messagin
g.HeaderHandler handler) [0x00000]
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) [0x00000]
--8<----------------------------------------------
If we have a look at method ObjectManager.RaiseOnDeserializingEvent we'll see that for NET_2_0 configuration it is defined as follows:
--8<----------------------------------------------
#if NET_2_0
public void RaiseOnDeserializingEvent (object obj)
{
SerializationCallbacks sc = SerializationCallbacks
.GetSerializationCallbacks (obj.GetType ());
sc.RaiseOnDeserializing (obj, _context);
}
void RaiseOnDeserializedEvent (object obj)
{
SerializationCallbacks sc = SerializationCallbacks
.GetSerializationCallbacks (obj.GetType ());
sc.RaiseOnDeserialized (obj, _context);
}
#endif
--8<----------------------------------------------
while in System.Runtime.Serialization.SerializationCallbacks.cs method GetSerializationCallbacks is defined as:
--8<----------------------------------------------
public static SerializationCallbacks GetSerializationCallbacks (Type t)
{
lock (cache.SyncRoot) {
SerializationCallbacks sc = (SerializationCallbacks) cache [t];
if (sc == null) {
sc = new SerializationCallbacks (t);
cache [t] = sc;
}
return sc;
}
}
--8<----------------------------------------------
It shouldn't be possible for method GetSerializationCallbacks to receive null value as a parameter (because in this case the exception should be generated in RaiseOnDeserializedEvent method. Or is it possible in mono that obj.GetType() is equal to null while obj itself is not equal to null?
Best regards,
Vadim Guzev
P.S. Additional info:
mono --version
Mono JIT compiler version 1.2.2.1, (C) 2002-2006 Novell, Inc and Contributors. www.mono-project.com
TLS: __thread
GC: Included Boehm (with typed GC)
SIGSEGV: normal
Disabled: none
uname -a
Linux skif 2.4.27 #1 SMP Thu Apr 14 15:25:11 MSD 2005 i686 athlon i386 GNU/Linux
I'm using gmcs compiler to compile my programs.
P.P.S. I can't create clear example which demonstrates this problem, because it appears only when I'm using distributed metacluster environment (where several clusters execute one program written in MC# language). Even when I'm using one cluster it works as expected, so I suppose that the only way to find the reason of these exceptions is to analyze the code of those two methods... Please, help me!
More information about the Mono-devel-list
mailing list