473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

IndexOutOfRangeException 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.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.Dictionary`2.Resize()
at System.Collections.Generic.Dictionary`2.Insert(TKe y key, TValue value,
Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
<our code removed from callstack>

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

Jul 5 '06 #1
5 11188
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**********@gmail.comwrote in message
news:%2***************@TK2MSFTNGP05.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<string, intso if
string.GetHashCode 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.Resize, but could not find any reason for
IndexOutOfRangeException 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**********@gmail.comwrote in message
news:%2****************@TK2MSFTNGP03.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
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...
9
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...
1
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(...
0
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...
3
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...
2
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. ...
2
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)...
0
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...
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.