Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

AggregateEnumerator

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Random - 18 Jul 2007 18:44 GMT
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?
Jon Skeet [C# MVP] - 18 Jul 2007 18:58 GMT
> 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)
[quoted text clipped - 3 lines]
> 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)?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Random - 18 Jul 2007 19:22 GMT
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.

>> 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,
[quoted text clipped - 7 lines]
> 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)?
Jon Skeet [C# MVP] - 18 Jul 2007 19:44 GMT
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.