AggregateEnumerator

  • Thread starter Thread starter Random
  • Start date Start date
R

Random

I find this very odd. I'm using GetEnumerator from the my HttpRuntime
cache, and I'm trying to cast the result to a Dictionary(Of String, Object)
class. It doesn't work. The error says "Unable to cast object of type
'System.Web.Caching.AggregateEnumerator' ...".

But I can't find the AggregateEnumerator class anywhere. What's going on
here?
 
Random said:
I find this very odd. I'm using GetEnumerator from the my HttpRuntime
cache, and I'm trying to cast the result to a Dictionary(Of String, Object)
class. It doesn't work. The error says "Unable to cast object of type
'System.Web.Caching.AggregateEnumerator' ...".

But I can't find the AggregateEnumerator class anywhere. What's going on
here?

The result of calling GetEnumerator os the AggregateEnumerator. Why did
you think you'd be able to cast it to a Dictionary(Of String, Object)?
 
I tried it because the Cache.GetEnumerator method returns
IDictionaryEnumerator, and the Dictionary(Of TKey, TValue) uses that
interface.

I'm not worried about that, what I'm really trying to do is get the Cache
items in a class that I can DataBind without going looping through an
enumeration manually... so I'm trying a number of things. But I'm confused
about not being able to find the AggregateEnumerator class in the Object
Browser, or being able to declare a variable as AggregateEnumerator. It's
as though it doesn't really exist.
 
Random said:
I tried it because the Cache.GetEnumerator method returns
IDictionaryEnumerator, and the Dictionary(Of TKey, TValue) uses that
interface.

When a method's return type is an interface, you should try to just use
the interface, rather than assuming a particular implementation. Even
if it had worked right now, there's nothing to say it would still work
with a future version of .NET.
I'm not worried about that, what I'm really trying to do is get the Cache
items in a class that I can DataBind without going looping through an
enumeration manually... so I'm trying a number of things. But I'm confused
about not being able to find the AggregateEnumerator class in the Object
Browser, or being able to declare a variable as AggregateEnumerator. It's
as though it doesn't really exist.

No, it's just an internal type - an implementation detail which
implements a public interface.
 
Back
Top