473,938 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IndexOutOfRange Exception being thrown from a call to Dictionary.Add?

This does not seem to be a documented exception.
See: http://msdn2.microsoft.com/en-us/library/k7z0zy8k.aspx
System.IndexOut OfRangeExceptio n: Index was outside the bounds of the array.
at System.Collecti ons.Generic.Dic tionary`2.Resiz e()
at System.Collecti ons.Generic.Dic tionary`2.Inser t(TKey key, TValue value,
Boolean add)
at System.Collecti ons.Generic.Dic tionary`2.Add(T Key key, TValue value)
<our code removed from callstack>

Any ideas on what would cause this?
--
Adam Clauss

Jul 5 '06 #1
5 11269
The only thing I can think of is if your key instance is itself throwing
this exception in the GetHashCode() or Equals() methods; do you have any
(cut-down) sample code to illustrate this?

Marc
Jul 5 '06 #2
"Marc Gravell" <ma**********@g mail.comwrote in message
news:%2******** *******@TK2MSFT NGP05.phx.gbl.. .
The only thing I can think of is if your key instance is itself throwing
this exception in the GetHashCode() or Equals() methods; do you have any
(cut-down) sample code to illustrate this?
The Dictionary in question is: Dictionary<stri ng, intso if
string.GetHashC ode were to be throwing this exception, I don't know what I
could do about it anyway...

Unfortunately I'm not sure if I can trim this down any. This is part of a
rather complex system - and we cannot actually duplicate this here in our
development environment. It is being seen at the client's site.

I even poked around using Reflector into that last call to
Dicitonary.Resi ze, but could not find any reason for
IndexOutOfRange Exception to be thrown.

--
Adam Clauss
Jul 5 '06 #3
OK, probably rule that one out then! (assuming you aren't passing in your
own comparer).

Next try: is there any threading going on? Perhaps one thread is removing
things as another thread is causing resize... I can't see any specific lock
in reflector, so I assume that these methods are *not* thread-safe without
your own sync.

Marc
Jul 5 '06 #4
aside: if this is a aspnet project and the dictionary is static, then the
same applies even without your own threads

Apols if this seems obvious; it comes as quite a shock to some people...

Marc
Jul 5 '06 #5
"Marc Gravell" <ma**********@g mail.comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
aside: if this is a aspnet project and the dictionary is static, then the
same applies even without your own threads

Apols if this seems obvious; it comes as quite a shock to some people...

Marc
Haha, I welcome anything, obvious or otherwise. And no - not ASP.NET. It's
a Windows Service.

Still the threading is a possibility I am looking into. We are doing some
synchronization , but I am wondering if we have a case which is slipping
through.

--
Adam Clauss
Jul 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1795
by: Juan Galdeano | last post by:
Hi, I'm working on an ONIX project and when I try to validate or read XML files C# gives me this exception: System.IndexOutOfRangeException at System.Xml.XmlScanner.ScanDtdContent() at System.Xml.Schema.DtdParser.ScanDtdContent() at System.Xml.Schema.DtdParser.ParseDtdContent() at System.Xml.Schema.DtdParser.ParseDocTypeDecl()
9
16577
by: Tylius | last post by:
This one line is causing the issue, I've searched all over the net, but I can't seem to figure out why public static void Main(string args) { Console.WriteLine("Dice Roller"); try { int num_dice = int.Parse(args); // This is the problem
1
2160
by: Stephen.Haeney | last post by:
I have a datagrid bound to a strongly typed custom collection. I have a Delete button on my form that calls the following code: if ( this.BindingContext.Count > 0 ) { myDataSource.RemoveAt( this.BindingContext.Position ); } I was expecting the button press to remove the elevant row from the
0
2142
by: scotthutchinson | last post by:
I have a .NET Remoting object hosted in IIS6 on Windows Server 2003 (happens before and after installing SP1) at an endpoint (ASP.NET application virtual folder) named "CompanyXYZReporting". The remoted object is called several times every day and works perfectly except every 2-3 weeks when we call the remoted object, the response returns the error shown below. Does anyone have any clues how to resolve this problem? Server Error in...
3
1979
by: Giovanni Bassi | last post by:
Hello Group, I am running an operation in a different thread. There are resources that are released when the thread is done running. This is done at the end of the execution as it raises an event, and then the operation handling this event calls threaded object's dispose method. The problem is: If an exception is thrown the event is never raised, the operation never executes dispose and my resources get stuck on the memory until the app...
2
8031
by: | last post by:
Using the following against a sql database, I get a system.IndexOutOfRangeException for the column name Add_Date which is valid field name and is a datetime field. All the other columns work ok. Does anybody have any ideas. I'm new with .Net and this is driving me crazy. Dim intTblAddDate As Integer = myReader.GetOrdinal("Add_Date") Thanks in advance... Dick Bellnier
2
2678
by: Dot net work | last post by:
Hello, My simple code is here: Public Class MyDictionary Inherits System.Collections.DictionaryBase Private Class MyElement Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean End Function
0
1123
by: =?Utf-8?B?TWlrZQ==?= | last post by:
I have a .NET 2.0 app running on Server 2003. Intermittently, a request ends up on the error page with "Index was outside the bounds of the array". The stack trace shows MyBase.New() being invoked from the constructor in Global.asax.vb (below). I do not have any code in MyBase.New(). Any help? System.Collections.ArrayList.Add(Object value) +43 CustomerManager.Global..ctor() in C:\Inetpub\wwwroot\CustomerManager\Global.asax.vb:12...
0
2985
by: =?Utf-8?B?aW1yYW4uYQ==?= | last post by:
Hi all, I am having a problem with inserting rows in to my datagridview control. The datagridview is bound to a bindingsource with a filter set. If i try and add a row to the datagridview while the filter is set i get an IndexOutOfRangeException specifying that the index of the row i have just added does not exist. I have managed to narrow down the conditions that cause the error and it seems to surface if i have a filter set for a...
0
11524
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11288
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9857
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8218
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6295
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4904
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3501
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.