Solved

throwing error in code, how do i fix please

Posted on 2006-11-09
21
300 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:Johnny
21 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 17906670
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
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17906718
Sure, but declaring NodeKeyValueEnumerator as...

Class NodeKeyValueEnumerator
    Implements IDictionaryEnumerator


... would be better.
0
 

Author Comment

by:Johnny
ID: 17906780

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
 

Author Comment

by:Johnny
ID: 17906797
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
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17906814
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
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17906833
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
 

Author Comment

by:Johnny
ID: 17906942
i added
Imports System.Collections.Specialized
to the top of the form1

im still getting the error
0
 

Author Comment

by:Johnny
ID: 17907016
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
 

Author Comment

by:Johnny
ID: 17907063
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
 

Author Comment

by:Johnny
ID: 17907172
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Johnny
ID: 17907418
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
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17907437
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
 

Author Comment

by:Johnny
ID: 17908624
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
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17908663
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
 

Author Comment

by:Johnny
ID: 17908889
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
 

Author Comment

by:Johnny
ID: 17908920
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
 

Author Comment

by:Johnny
ID: 17909427
               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
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17909637
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
 

Author Comment

by:Johnny
ID: 17909775
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
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 500 total points
ID: 17910007
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
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17911137
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now