When Breaking Changes Actually Break Stuff

It’s funny how breaking changes actually…well, break stuff sometimes.  I’ve had an issue on JK.com that I’ve been trying to track down for a while now:  Search was completely broken and for the life of me I couldn’t figure out why.  I won’t bore anyone with the troubleshooting steps I took, but long story short there was a change to the String.GetHashCode algorithm from .Net 1.1 to 2.0.  It says it right there in the documentation:

The behavior of GetHashCode is dependent on its implementation, which might change from one version of the common language runtime to another. A reason why this might happen is to improve the performance of GetHashCode. If you require the behavior of GetHashCode be constant, override the runtime implementation of GetHashCode with an implementation of your own that you know will never change.

Eric Lippert further emphasizes this here:

Finally, the string hash algorithm is not an industry standard and is not guaranteed to produce the same behaviour between versions. And in fact it does not. The .NET 2.0 CLR uses a different algorithm for string hashing than the .NET 1.1 CLR. If you are saving .NET 1.1 CLR hash values in a database then you will not be able to match them when you upgrade to 2.0.

How does this affect the search functionality in Community Server?  Well, for starters CS uses a string hash to tokenize posts (the TokenizeKeywords method) in the cs_searchBarrel table.  So if you’re running CS2.0 under asp.net 2.0, search will be broken as the keys won’t match.  Period.  The fix is easy enough (well, I say that now)…simply truncate your cs_searchBarrel table and update all of your IsIndexed column values in cs_Posts to 0, and CS will do the rest for you by rebuilding the search tables.  I must have truncated my cs_searchBarrel table about a thousand times trying to fix this, but failed to do the latter step.  CS won’t index posts that already have IsIndexed set to true, which of course makes sense once you think about it…this would be disastrous performance-wise for large sites if the search job had to reindex every post on each pass.

So if you’re running CS2.0 on asp.net 2.0, more than likely your search is broken and you may not have realized it.  The bigger point is what Eric pointed out:  Don’t use GetHashCode to uniquely identify data as it’s not guaranteed to remain consistent across .Net version changes.  Google knew about this long before I did.


# Dan Bartels said:

One of our community developers Jayson Knight posted about a key Gotcha with CS Standard Search when...

Sunday, February 26, 2006 10:32 PM
# Chris Kirby said:

Thanks for pointing this out Jayson...I didn't even notice that my search was broken.

Tuesday, February 28, 2006 12:47 AM
# Jayson Knight said:

Hey Chris...yeah, that's one of my big worries.  It's even more worrisome because I've seen virtually no mention of it whatsoever over on CS.org, and I know a ton of the CS site admins upgraded to both CS2.0 AND asp.net 2.0, which means search isn't working on any of those sites and they don't know yet.  This also isn't really something that would be picked up on by users of the site...they would do a search, get back crappy results, and then move on w/o mentioning to anyone as it's subtle to the untrained eye.  I'm guilty of this myself, I rarely ping site admins unless it's an in your face runtime error.

Maybe I'll push the guys over at Telligent to make a formal announcement.  I don't think they'll patch the upgrade scripts, but at least it will help get the word out.

Tuesday, February 28, 2006 1:04 AM
# TechnogIT » Blog Archive » Search broken by CS upgrade said:

PingBack from http://myity.wordpress.com/2006/08/15/search-broken-by-cs-upgrade/

Tuesday, August 15, 2006 4:58 AM
# Souplog said:

The search function on the soup blog has been fixed. I inadvertently broke it when I upgraded Community

Saturday, August 19, 2006 4:51 AM
# Wizards Space said:

If you recently upgraded your Community Server site and the search is not working properly or not at

Saturday, August 19, 2006 8:17 AM
# Notes from the Field said:

I noticed that after upgrading CS from v2.0 to v2.1 (during which I also moved from using .NET 1.1 to

Saturday, August 26, 2006 2:44 PM
# Kingsley.Tagbo said:

I just realized today that the Searching Feature on this site was broken while migrating from CS 2.0

Wednesday, August 30, 2006 4:54 AM
# SwoofWare » Community Server Search Fix said:

PingBack from http://www.swoofware.com/posts/2006/09/12/community-server-search-fix/

Tuesday, September 12, 2006 10:35 PM
# protected virtual void jaysonBlog { said:

I recently noticed a reasonable spike in traffic around here a few days ago; turns out an entry of mine

Wednesday, February 7, 2007 10:01 PM