Scott Hanselman

You must implement the Add(System.Object) method on MyClass because it inherits from IEnumerable

August 24, '05 Comments [3] Posted in ASP.NET | Learning .NET | XmlSerializer | Africa
Sponsored By

Peter was getting the error "You must implement the Add(System.Object) method on MyClass because it inherits from IEnumerable" while serializing an object. He added an Add() method and the error went away, but he was rightfully confused by this odd message because IEnumerable doesn't require an Add as part of its contract! The error message arguably uses the word "implement" in a way that implies something about the interface in question.

Remember that the XmlSerializer has to serialize and deserialize, and does so only via public means. For something that implements IEnumerable, there'd be no way to get objects back in without something like an Add.

Sairama pointed to this paragraph buried in the MSDN docs:

The XmlSerializer gives special treatment to classes that implement IEnumerable or ICollection. A class that implements IEnumerable must implement a public Add method that takes a single parameter. The Add method's parameter must be of the same type as is returned from the Current property on the value returned from GetEnumerator, or one of that type's bases. A class that implements ICollection (such as CollectionBase) in addition to IEnumerable must have a public Item indexed property (indexer in C#) that takes an integer, and it must have a public Count property of type integer. The parameter to the Add method must be the same type as is returned from the Item property, or one of that type's bases. For classes implementing ICollection, values to be serialized will be retrieved from the indexed Item property, not by calling GetEnumerator

Now playing: Ladysmith Black Mambazo - N'kosi Sikeleli Afrika (God Bless Africa)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

The ISAPI equivalent of Response.AppendToLog

August 24, '05 Comments [1] Posted in ASP.NET | Web Services
Sponsored By

In ASP.NET the Response object has a very useful method called AppendToLog. It was also around in the Classic ASP days. The Response object hangs off the HttpContext. If you're running with the context of an HttpRequest you can always get ahold of the current HttpContext via the static HttpContext.Current.

However, not everyone executes within managed code in ASP.NET. We've got a bunch of ISAPI code that is all C++/ATL/MFC. Within MFC you can get ahold of the context via the CHttpServerContext class. This class isn't as friendly as the whole Request/Response ASP model.

If you want to get to the really useful stuff you have to run through a 3rd Class API actually named ServerSupportFunction that's hanging off an Extension Control Block. Lame. The second parameter is a DWORD that indicates the function you're trying to call. Since we were trying to call the equivalent of Response.AppendToLog we would use HSE_APPEND_LOG_PARAMETER. The additional information you're trying to log will show up in the cs-uri-query extended field within IIS if you're using the W3C Extended Log File Format. You'll need to go into IIS Properties and enable the logging of this field.

So, doing this in managed code:

HttpContext.Current.Response.AppendToLog(strFoo);

Is this in unmanaged "classic" C++ ISAPI:

m_pCHttpServerContext->m_pECB->ServerSupportFunction( 
                                m_pCHttpServerContext->m_pECB->ConnID , 
                                HSE_APPEND_LOG_PARAMETER , 
                                szFoo, 
                                &dwFooLen , 
                                NULL 
                            );

Big ups to Paul Gomes from Corillian for figuring this out! And no I'm not off vacation yet; my wife is asleep. :)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

More Interesting Maps

August 24, '05 Comments [8] Posted in Musings | Tools
Sponsored By

Mapsa9I'd mentioned Amazon's foray into maps earlier, but they've gone even farther and launched http://maps.a9.com with "BlockView Images" for a bunch of cities. It's very Ajax-esque and while I think the dragging of the magnifying glass could use some work (I keep expecting it to work like Google Maps) it's a pretty interesting concept.

UPDATED: This is cool, adding A9 images to Google Maps.

Here's the lay of the land as I see it.

Interesting Map Sites

Amazing Map Fat Clients

GPS Map Clients with DVDs

Map Sites That No Longer Serve a Purpose

Map Sites That Totally Missed The Boat But Are Still Used As Verbs

Map Sites That Should Have Been Integrated with Another Map Site But Aren't For Whatever Reason I'm Not Privy Too But That's Still No Excuse

 

 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

August 2005 Quickie Update

August 23, '05 Comments [10] Posted in ASP.NET | Nant | Africa
Sponsored By

Hey folks, I'm still on vacation with the family, but so you won't stop reading my blog and wonder if there will ever be an update again, here's what I've been doing in no particular order.

  • New Music: I've been totally digging/obsessed with this South African band called "freshlyground." They are an eclectic mix of pop/jazz/xhosa and they're a blast. You can have a listen here. I highly recommend "Mowbray Kaap" on their album "Nomvula." If you can find it, get it.
  • Sidebars galore: Google Desktop now has a Sidebar. Now that I've completely switched over to Microsoft Desktop Search, it's surprising that Google beat them to this. I've installed it and am running it with the search index off. I think I still like Konfabulator Widgets though, and it'd be interesting to write a Konfabulator Sidebar. (BTW, both are free, so at least download Konfabulator! Ya, I know it's a memory hog, so what?)
  • Speed: FireTune seems like a great idea but I always wonder why apps can't just tune themselves?
  • Maps: It's lovely that Omar is looking for reasons not to use Google and that he's stopped using it for maps. However, is it just me or is Virtual Earth virtually unusable? I can't figure out how to do a simple address search without double-taking. The interface is truly obtuse and the results are unforgiving. Google Maps is wonderfully elegant. Maybe it's just me. He loves the MSN Weather Add-In also, but I yawn at that since I'm using ForecastFox.
  • Babies: The baby is chugging along. We're at 25 weeks right now. It's been the non-pregnancy-pregnancy. She's had no sickness, no sleepnessness, no weird food. Nada. We hope the next 15 weeks are as easy to handle - certainly the next 18 years won't be as easy!
  • Ajax: I've been looking at a number of Ajax libraries lately, and I'm disillusioned by the bizarre drama going around around Ajax.net. I can't fathom why the guy didn't just put up a zip file then use SourceForge. The code's far to complex for what it does anyway, IMHO. I have been impressed by Jason Diamond's implementation though, which is nice and simple. As of this writing his latest is here. I've also checked out Mochikit and a number of others.
  • Del.icio.us: This continues to rock my world. If you're interested you can subscribe to my del.icio.us RSS feed and see what I'm currently bookmarking. If you end up using del.icio.us, for gosh sake DO use the BookMarkLets. They are a treat.
  • Fun: Here's my list of hilarious or poignant blogs I'm reading/subscribed to...
  • Um, OK: Aeon Flux. At least they tried.

Now playing: Freshlyground - Touch In The Night

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Undeleting Digital Photo Files from Removable Media

August 19, '05 Comments [8] Posted in Reviews | Tools
Sponsored By

Digital Picture Recovery just saved my ass. My 512 Meg SD card was erased (Delete All Files) by my nephew, causing us to lose the last week of my Mother-in-law's trip to the states. OMG. Seriously.

Yes, I know how FAT works, yes I tried a number of tools, but this wasn't a matter of ?eleted files, these were orphaned. I tried 3 different undeletes, paying for 1, all without success. Each of the failures could find only 4 files, and there were 373 missing files. Also, the failed programs took seconds to search, which wasn't a comforting sign. At least lie to me and take some time, eh?

However, Digital Picture Recovery searched for 15 minutes and found all 373 files, as well as a dozen from literally months ago. 

Fan-freaking-awesome. Saved. Whew. 

UPDATE: Forgot, here's a few of the saved pics. My M-in-law from Zim is visiting our home for the first time.

CIMG3518 (Medium)

Recovered527539 (Medium)

 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.