Solved

throwing error in code, how do i fix please

Posted on 2006-11-09
21
310 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb.net winforms sizing/resolution? 4 53
SSRS 2016 Rendering HTML tables 3 55
vb.net sendkey 4 17
Visual Basic 6: Code needed for TripleDES Encryption/Decryption 13 30
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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