473,487 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

IList (of Type) Enumerator Error

I have two classes. One (FrontierApplication) is a definition of a
record from a table. The other (FrontierApplicationCollection) is the
collection of the first class. Below is how they are defined. I get
an error when iterating through the collection. The error I get is
"Unable to cast object of type 'ArrayListEnumeratorSimple' to type
'System.Collections.Generic.IEnumerator'" The error occurs in the
collection class from the GetEnumerator function. When I try to use
the "For Each . . . " below it generates the error. When I use the
"For i as integer = 0 to . . . " it works correctly. I want to use the
"For Each". Why do I get this error?

Here is the code:

Public Class FrontierApplication

... generic stuff with properties

End Class

Public Class FrontierApplicationCollection
Implements IList(Of FrontierApplication)

Private myArrayList As New ArrayList

... generic IList properties, subs and function

Public Function GetEnumerator() As
System.Collections.Generic.IEnumerator(Of FrontierApplication)
Implements System.Collections.Generic.IEnumerable(Of
FrontierApplication).GetEnumerator
Return myArrayList.GetEnumerator() ' Error occurs here
End Function

End Class

Private myFrontierApplications As New FrontierApplicationCollection

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
'
' This generates the error.
'
'For Each f As FrontierApplication In
myFrontierApplications
' Debug.WriteLine(f.ApplicationName)
'Next
'
' This works just fine.
'
For i As Integer = 0 To myFrontierApplications.Count - 1

Debug.WriteLine(myFrontierApplications(i).Applicat ionName)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Jan 16 '07 #1
2 4046

Paul wrote:
I have two classes. One (FrontierApplication) is a definition of a
record from a table. The other (FrontierApplicationCollection) is the
collection of the first class. Below is how they are defined. I get
an error when iterating through the collection. The error I get is
"Unable to cast object of type 'ArrayListEnumeratorSimple' to type
'System.Collections.Generic.IEnumerator'" The error occurs in the
collection class from the GetEnumerator function. When I try to use
the "For Each . . . " below it generates the error. When I use the
"For i as integer = 0 to . . . " it works correctly. I want to use the
"For Each". Why do I get this error?

Here is the code:

Public Class FrontierApplication

... generic stuff with properties

End Class

Public Class FrontierApplicationCollection
Implements IList(Of FrontierApplication)

Private myArrayList As New ArrayList
The array list is yur problem... Change it to a List from
System.Collections.Generic.

--
Tom Shelton

Jan 16 '07 #2
Thanks Tom. That worked.

Jan 16 '07 #3

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

Similar topics

4
10611
by: leslie_tighe | last post by:
Hello, I have a method on a com+ object that is returning an array of objects. I know the array is popluated as calls to check the ubound and lbound show valid values. However, any calls to...
4
11938
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
3
3567
by: Martin Lacoste | last post by:
Is there some issue with using too many left/right/mid/len functions in queries? Depending on the usage, they work fine, but... then there's here: SELECT Master_CAO.Incipit,...
0
2229
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
0
280
by: Alex | last post by:
Hi, is it possible to determine exactly what type of error/exception was thrown from a try catch block bt simple catching the generic error. by this I mean, suppose I have the follwoing code...
1
2026
by: jodyblau | last post by:
I am getting a type mismatch message under strange circumstances. Here's whats going on: 1. I have split the database into a front end and a back end. 2. I have compiled the project. 3. ...
2
22516
by: venu reddy | last post by:
Hi all, I wrote an example code like this. I am getting error as " conversion to non-scalar type requested error". help me!!. #include<string.h> typedef struct { int val; char data;
2
1973
by: colintis | last post by:
Since I just use MS Access 2003 to compact and repair a corrupted database, more errors were shown from it that weren't existed before the corruption. There are 2 errors I'm currently having: ...
1
3986
by: sharbha | last post by:
I am experiencing a VBScript runtime error. The error message is: "(0x800A000D)Type mismatch error" Here is my code: <% dim temp temp=session("items") ...
0
7108
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7181
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...
1
6847
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...
0
5445
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,...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1383
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 ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
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...

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.