views:

109

answers:

1

I have an existing app in which I made the mistake of using String.GetHashCode and persisting it to disk. Now that I'm upgrading the app to .Net 2.0 I find that that decision has come back to bite me in the butt.

I'm interested to know if anyone knows about a .Net 2.0 implementation of a .Net 1.1 compatible string hashing algorithm.

Obviously the best solution would be to buy myself a time machine and go back to 2002 and kick myself in the shin for even considering using the hashcode this way. Since that doesn't appear likely I'm looking for a workaround. I have existing users with this data on their systems so it's not possible for me to make one big conversion of the hashes or anything like that.

With the change to 2.0 I will update the code so it uses MD5 or SHA of course.

I considered extracting the String.GetHashCode source from Mono but since Mono is GPL and my app is commercial that really isn't an option. I don't even know if the Mono implementation is compatible with the MS .Net implementation since the contract for GetHashCode wouldn't require it to be compatible.

Any ideas?

+4  A: 

You're not the only one, it seems: Getting .NET 1.1 CLR String Hash Codes In The .NET 2.0 CLR

That links to BackCompatibleStringComparer, which (allegedly, I can't verify) shows the implementation of the old GetHashCode().

Alex Brasetvik
Thanks for the tip. I knew StackOverflow would come through for me.Interesting that they would include it in the 2.0 framework but not make it publicly accessible. Extra interesting that it's called from DataObject and from the Enterprise Library. It would seem some of their internal devs made the same mistake I did.
Steve Hiner