Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

throwing error in code, how do i fix please

Posted on 2006-11-09
21
Medium Priority
?
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

688 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