473,385 Members | 1,796 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,385 software developers and data experts.

hashtable unhandled exception

I am trying to utilize Hashtable to facilitate mapping one value to
another. I have successfully added several such pairs. When using the
enumerators to find keys upon subsequent manipulation, I get the
following error. Any ideas why this is? Maybe I didn't initialize the
table properly?

An unhandled exception of type 'System.InvalidOperationException'
occurred in mscorlib.dll
Additional information: Collection was modified; enumeration operation
may not execute.

My code is thusly:

if (this->m_registryKey)
{
IEnumerator* keyEnum
= this->m_stringDict->Keys->GetEnumerator();

while (keyEnum->MoveNext())
{
String* strValue;

String* strKey = __try_cast<String*>(keyEnum->Current);

if (strValue = __try_cast<String*>(
this->m_registryKey->GetValue(strKey)))
{
this->Value[strKey] = strValue;
}
else
{
this->m_registryKey->SetValue(
strKey, this->m_stringDict->Item[strKey]);
}
}
}
Nov 17 '05 #1
2 2040
Mike wrote:
I am trying to utilize Hashtable to facilitate mapping one value to
another. I have successfully added several such pairs. When using the
enumerators to find keys upon subsequent manipulation, I get the
following error. Any ideas why this is? Maybe I didn't initialize the
table properly?

An unhandled exception of type 'System.InvalidOperationException'
occurred in mscorlib.dll
Additional information: Collection was modified; enumeration operation
may not execute.


That exception means that the collection was modified since the enumerator
was created.

The way the .NET collection classes work is this:

1. Each collection maintains a "version number".
2. Whever an object is added to or removed from the container, the version
number is incremented.
3. When an enumerator for a collection is created, it copies the version
number of the container.
4. Whever the enumerator is used, the version number captured at creation
time is compared to the current version number of the container.
5. If the versions don't match, the exception you're seeing is thrown.

-cd
Nov 17 '05 #2
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam > wrote in message news:<eA**************@tk2msftngp13.phx.gbl>...
The way the .NET collection classes work is this:

1. Each collection maintains a "version number".
2. Whever an object is added to or removed from the container, the version
number is incremented.
3. When an enumerator for a collection is created, it copies the version
number of the container.
4. Whever the enumerator is used, the version number captured at creation
time is compared to the current version number of the container.
5. If the versions don't match, the exception you're seeing is thrown.


Makes sense. I gather Hashtable isn't such a good substitute for the
traditionally though of Map for this reason? In other words, I've
build a table of keys (above), and updating those keys with values
will increment the table version making the keys, much less its
enumerator, worthless. At least in an attempt to substitute as a Map.
Nov 17 '05 #3

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

Similar topics

5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
33
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are...
2
by: Noozer | last post by:
Code sample: dim hash as Hashtable 'Declare Hashtable .... hash.add (picOne.image, "picture") 'Error here picOne is a picturebox added to the form at design time with a GIF image applied....
5
by: Lucvdv | last post by:
Can someone explain why this code pops up a messagebox saying the ThreadAbortException wasn't handled? The first exception is reported only in the debug pane, as expected. The second (caused by...
5
by: Dick | last post by:
Hello, I'm trying to serialize a class with a Hashtable within: ' Class code: Imports System.Collections Class clsOptions Public countID As Integer Public persons As New Hashtable End Class
5
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can...
0
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks...
4
by: WhiskyRomeo | last post by:
I am trying to implement a webservice that returns a HashTable as a result <WebMethod()> Public Function GetAppData() As Hashtable Dim List As New Hashtable 'omitted code Return List End...
9
by: Nick Vaughan | last post by:
While running some long term tests on our Broadcast SDK one of our thread dropped out because an exception had been thrown: Exception: System.ArgumentOutOfRangeException Message: Load factor...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.