[Mono-dev] Bug in System.Collections.Generic.Dictionary

Arno Rehn mono-devel at arnorehn.de
Wed Dec 17 13:55:04 EST 2008


Hi,

I've recently discovered a bug in the Dictionary class.
After really fast insertions (ca. 9000-1000) and some removals in between it 
crashes with 

UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception 
has been thrown by the target of an invocation. ---> 
System.IndexOutOfRangeException: Array index is out of range.                                                            
  at 
System.Collections.Generic.Dictionary`2[System.IntPtr,System.WeakReference].set_Item 
(IntPtr key, System.WeakReference value) [0x00116] in /var/tmp/portage/dev-
lang/mono-2.0.1/work/mono-2.0.1/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:180                                                                                                                     
  at Qyoto.SmokeMarshallers.MapPointer (IntPtr ptr, IntPtr instancePtr, 
Boolean createGlobalReference) [0x00016] in 
/home/pumphaus/dev/KDE/kdebindings/csharp/qyoto/src/SmokeMarshallers.cs:361                                                           
  at (wrapper native-to-managed) Qyoto.SmokeMarshallers:MapPointer 
(intptr,intptr,bool)                                      
  at (wrapper managed-to-native) Qyoto.SmokeInvocation:CallSmokeMethod 
(intptr,int,intptr,intptr,int)                        
  at Qyoto.SmokeInvocation.Invoke (System.String mungedName, System.String 
signature, System.Type returnType, System.Object[] args) [0x003d1] in 
/home/pumphaus/dev/KDE/kdebindings/csharp/qyoto/src/SmokeInvocation.cs:610                               
  at Qyoto.QRectF..ctor (Double left, Double top, Double width, Double height) 
[0x0000d] in /home/pumphaus/dev/KDE/kdebindings/csharp/qyoto/core/QRectF.cs:30                                                                                             
  at 
Synapse.QtClient.AvatarGrid`1+GraphicsRosterItem`1[Synapse.UI.AccountItemPair,Synapse.UI.AccountItemPair].BoundingRect 
() [0x00000]                                                                                                                  
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke 
(object,object[],System.Exception&)             
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags 
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, 
System.Globalization.CultureInfo culture) [0x00057] in /var/tmp/portage/dev-
lang/mono-2.0.1/work/mono-2.0.1/mcs/class/corlib/System.Reflection/MonoMethod.cs:157                                                                    
  --- End of inner exception stack trace ---                                                                                 
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags 
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, 
System.Globalization.CultureInfo culture) [0x00071] in /var/tmp/portage/dev-
lang/mono-2.0.1/work/mono-2.0.1/mcs/class/corlib/System.Reflection/MonoMethod.cs:167                                                                    
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] 
parameters) [0x00000] in /var/tmp/portage/dev-
lang/mono-2.0.1/work/mono-2.0.1/mcs/class/corlib/System.Reflection/MethodBase.cs:110                                           
  at Qyoto.SmokeInvocation.InvokeMethod (IntPtr instanceHandle, IntPtr 
methodHandle, IntPtr stack) [0x00416] in 
/home/pumphaus/dev/KDE/kdebindings/csharp/qyoto/src/SmokeInvocation.cs:216                                                                
  at (wrapper native-to-managed) Qyoto.SmokeInvocation:InvokeMethod 
(intptr,intptr,intptr)                                   
  at (wrapper managed-to-native) Qyoto.SmokeInvocation:CallSmokeMethod 
(intptr,int,intptr,intptr,int)                        
  at Qyoto.SmokeInvocation.Invoke (System.String mungedName, System.String 
signature, System.Type returnType, System.Object[] args) [0x00399] in 
/home/pumphaus/dev/KDE/kdebindings/csharp/qyoto/src/SmokeInvocation.cs:603                               
  at Qyoto.QApplication.Exec () [0x00000] in 
/home/pumphaus/dev/KDE/kdebindings/csharp/qyoto/gui/QApplication.cs:278         
  at Synapse.QtClient.Client..ctor (System.String[] args) [0x00000]                                                          
  at Synapse.QtClient.Client.Main (System.String[] args) [0x00000]

I haven't been able to produce a test case, sadly. The only thing I can tell 
is that it's a Dictionary<IntPtr, WeakReference> and that the insertions are 
quite fast (they happen in ca. 5-10 secs.)
With a Hashtable instead of a Dictionary it seems to work well, though.

-- 
Arno Rehn
arno at arnorehn.de


More information about the Mono-devel-list mailing list