throwing error in code, how do i fix please

i am running/programming a ircd and im getting some errors

ERROR EX = System.InvalidCastException: Unable to cast object of type 'NodeKeyValueEnumerator' to type 'System.Collections.IDictionaryEnumerator'.
   at pureircd.Form1.ClearNullChanmembers() in D:\temp\phreikchat\phreikchat\phreikchat\IrcMX\Form1.vb:line 291
   at pureircd.Form1.expireaccessx(Object sender, ElapsedEventArgs e) in D:\temp\phreikchat\phreikchat\phreikchat\IrcMX\Form1.vb:line 275

line 291 is
ClearNullChanmembers()
line 275 is
en = ch.Members.Values.GetEnumerator
________________________________________________________
    Public Sub ClearNullChanmembers()
        Dim ch As Channel, chm As ChanMember, i As Integer
        Dim en As Collections.IDictionaryEnumerator

        For i = 0 To ChannelTab.GetUpperBound(0)
            ch = ChannelTab(i)
            If Not ch Is Nothing Then
StartCh:
                en = ch.Members.Values.GetEnumerator
                While en.MoveNext
                    chm = en.Value
                    If chm.aClient Is Nothing Then
                        ch.Members.Remove(en.Key)
                        GoTo StartCh
                    End If
                End While

            End If
        Next
    End Sub
________________________________________________________

if you should need anything else please ask
Thank you in advanace for any code and help you may provide
JohnnyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
VoteyDiscipleConnect With a Mentor Commented:
If it's a typecasting problem, then it being Nothing really won't have anything to do with it.  You'll have to get a better grasp of the type system used in this particular library.
0
 
TimCotteeCommented:
Hi Pern,

>         Dim en As NodeKeyValueEnumerator

This would seem to be the logical declaration, simply declaring it as the type that is referenced in the error message.


Tim Cottee
0
 
VoteyDiscipleCommented:
Sure, but declaring NodeKeyValueEnumerator as...

Class NodeKeyValueEnumerator
    Implements IDictionaryEnumerator


... would be better.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
JohnnyAuthor Commented:

Dim en As Collections.IDictionaryEnumerator
is the current declaring
 so how would i change this... i did not write this part and i dont fully understand it..

how would i use this
Class NodeKeyValueEnumerator
    Implements IDictionaryEnumerator

thanks
0
 
JohnnyAuthor Commented:
Error      1      Type 'NodeKeyValueEnumerator' is not defined.      D:\temp\phreikchat\phreikchat\phreikchat\IrcMX\Form1.vb      286      19      IrcMX.Net

changed to this... getting error right off

    Public Sub ClearNullChanmembers()
        Dim ch As Channel, chm As ChanMember, i As Integer
        'Dim en As Collections.IDictionaryEnumerator
        Dim en As NodeKeyValueEnumerator

        For i = 0 To ChannelTab.GetUpperBound(0)
0
 
VoteyDiscipleCommented:
Let's back up a step.

What is Channel?  Is this something you wrote?  Or is it something in the .NET framework that's just escaping my memory at the moment?

I assumed it was a class you wrote, using your own Enumerator.  If it's something from the framework or from a library, then TomCottee's solution would seem more appropriate.
0
 
VoteyDiscipleCommented:
Huh.  This is a framework class after all.  Google says it's in System.Collections.Specialized.NodeKeyValueEnumerator.

You'd have to either write out that full name, or declare at the top
Import System.Collections.Specialized


(Or is it Imports?  No matter how hard I try I can never remember which way is Java and which is .NET -- it would've killed 'em to use the same keyword?)
0
 
JohnnyAuthor Commented:
i added
Imports System.Collections.Specialized
to the top of the form1

im still getting the error
0
 
JohnnyAuthor Commented:
line 275
en = ch.Members.Values.GetEnumerator

going to each definition is:

Public Members As New Collections.Specialized.HybridDictionary(True)
System.Collections.Specialized.HybridDictionary.Values
System.Collections.IEnumerable.GetEnumerator
0
 
JohnnyAuthor Commented:
i decided to play a bit see what i get

ERROR EX = System.InvalidOperationException: Enumerator is positioned before the first element or after the last element of the collection.
   at System.Collections.Specialized.ListDictionary.NodeKeyValueCollection.NodeKeyValueEnumerator.get_Current()
   at pureircd.Form1.ClearNullChanmembers() in D:\temp\phreikchat\phreikchat\phreikchat\IrcMX\Form1.vb:line 294
   at pureircd.Form1.expireaccessx(Object sender, ElapsedEventArgs e) in D:\temp\phreikchat\phreikchat\phreikchat\IrcMX\Form1.vb:line 276

i changed line 275 to
en = ch.Members.Values.GetEnumerator.Current.ToString

i was looking to see if the type was wrong and should be string
0
 
JohnnyAuthor Commented:
converting it back now to original line

putting a break point on line 275, tells me that en = nothing
i can drill down the listing and get to the value in values

im gonna try to set the break point past the line and see if i can pick up the string


0
 
JohnnyAuthor Commented:
ive commented out part of it

                ''en = ch.Members.Values.GetEnumerator
                ''While en.MoveNext
                ''    chm = en.Value
                ''    If chm.aClient Is Nothing Then
                ''        ch.Members.Remove(en.Key)
                ''        GoTo StartCh
                ''    End If
                ''End While

and im not getting any more errors from that section
so its defantly in that section
doing breakpoints in any of it does not work as it does not find any values, en = nothing, no matter what i do.

0
 
VoteyDiscipleCommented:
Wait, so if you set a breakpoint at the line that reads "en = ch.Members.Values.GetEnumerator" then of course en hasn't been set yet, and is Nothing.  That's expected.  But if you "step over" that line it's still Nothing?

That's an awfully strange error to be getting in that case, but I'd say you've found your problem!
0
 
JohnnyAuthor Commented:
im asking in another question how to debug vb.net programs...

this may help me find problem..i know where it is i cant figure out how to fix it...maybe if empty then statement would be a good idea to bypass the block???

how would i go about doing that? and is that the correct way to handle this??
0
 
VoteyDiscipleCommented:
Tutorials on using the debugger are a little harder to find than tutorials on writing VB in general, but I like this one ( http://www.cs.uvm.edu/~upe/resources/debugging/visualBasicDebug/ ), which does come up near the top of the results.

It's written for VS 2003, so while all the techniques described there still apply in VS 2005, it's worth noting that 2005 makes a lot of debugging even easier.
0
 
JohnnyAuthor Commented:
ok lots of reading...

is there a way to fix the problem im having??

i think im gonna just award VoteyDisciple th points as you have been very helpful, and pointed me in the right direction too. but id still like answer if at all possible

0
 
JohnnyAuthor Commented:
would it be a good idea to instead of commenting it out..make a if empty statement then do something...be better then just bypassing it?
0
 
JohnnyAuthor Commented:
               If Not ch.Members.Values.GetEnumerator Is Nothing Then
                Else
                    en = ch.Members.Values.GetEnumerator
                    While en.MoveNext
                        chm = en.Value
                        If chm.aClient Is Nothing Then
                            ch.Members.Remove(en.Key)
                            GoTo StartCh
                        End If
                    End While
                End If

is that the right way to do this.... it doesn't seam to be giving any errors
0
 
VoteyDiscipleCommented:
I don't know anything about these particular classes, so I don't know whether a NodeKeyValueEnumerator is SUPPOSED to implement IEnumerable, or why, if it is, it's failing.

The last bit of code you posted is backwards, though -- that "Else" shouldn't be there.  It is a good idea to verify that the enumerator exists, but it should look like:

en = ch.Members.Values.GetEnumerator
If (Not ch Is Nothing) Then
    While (en.MoveNext)
        ' ... et cetera
    End While
End If
0
 
JohnnyAuthor Commented:
problemi s im getting an error on the line of
en = ch.Members.Values.GetEnumerator <<<--- problem
so i put it inside the if so it looks for it if nothing or not
0
 
Jeff CertainCommented:
I'd also point out that you could simplfy life by using For Each instead of handcrafting the trip through the enumerator.

The biggest issue that you're facing is probably the fact that the .NET enumerators aren't particularly robust -- they don't like you adding to or deleting from the collection under enumeration. Try making a copy of the collection, and deleting from it.
0
All Courses

From novice to tech pro — start learning today.