BUG: Unhandled exception error occurs when you enumerate through the Hashtable (815634)
The information in this article applies to:
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
SYMPTOMSIn a Remoting scenario, you may try to move the Enumerator
for a Hashtable from the server side to the client side. You do this so you can
iterate through the Hashtable on the client side. While you are enumerating
through the Hashtable, you may receive the following error
message: An unhandled exception of type
'System.InvalidOperationException' occurred in mscorlib.dll Additional
information: Collection was modified; enumeration operation may not
execute. CAUSEThe error occurs because the Hashtable Enumerator is a
MarshalByValue component. Therefore, the Hashtable stores the owner of the
Hashtable internally. When you request the Hashtable on the client side, the
Hashtable is deserialized on the client side. During deserialization, the
internal Hashtable is reconstructed. Therefore, the enumerator
fails.WORKAROUND To work around this problem, return the Hashtable directly
to the client. Do this instead of returning IEnumerator for the Hashtable. For example, locate the following code in the
ISystemSetting.cs file or in the ISystemSetting.vb file of the InterfaceDll
project. Sample code that can be used is included in the "More Information"
section of this article. Visual C# .NET CodeIEnumerator GetEnumerator(); Visual Basic .NET CodeFunction GetEnumerator() As IEnumerator Replace the IEnumerator function with the HashTable function as follows: Visual C# .NET CodeHashtable GetHashtable(); Visual Basic .NET CodeFunction GetHashTable() As Hashtable STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCES For additional information, click the following article
numbers to view the articles in the Microsoft Knowledge Base: 307933
HOW TO: Work with the HashTable Collection in Visual Basic .NET
309357 HOW TO: Work with the HashTable Collection in Visual C# .NET
Modification Type: | Minor | Last Reviewed: | 9/13/2005 |
---|
Keywords: | kbvs2002sp1sweep kbRemoting kbCollections kbClient kbBCL kbConfig kbbug KB815634 kbAudDeveloper |
---|
|