Paulo Morgado

.NET Development & Architecture

This Blog

Syndication

Search

Sponsored By

Tags

News

Unit Test Today! Get Typemock Isolator!

Projects

Books

 

Visitors

Visitor Locations

Community

Email Notifications

Archives

Profile

Disclaimer

The opinions and viewpoints expressed in this site are mine and do not necessarily reflect those of Microsoft, my employer or any community that I belong to. Any code or opinions are offered as is. Products or services mentioned are purchased by me, made available to me by my employer or the manufacturer/vendor which doesn't influence my opinion in any way.

Getting .NET 1.1 CLR String Hash Codes In The .NET 2.0 CLR

Everyone knows (or, should know) that values values retrieved from the GetHashCode method should not be persisted for later use, specially with strings, because:

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. [^]

Nevertheless, code that persist values retrieved from the GetHashCode method for later use can fall on your lap. And if you need to upgrade your code to, for example, use WCF or WF, you have a problem.

The usual solution would be to use Reflector to see how it was done in the 1.1 CLR and implement the same algorithm in the 2.0 runtime.

Unfortunately, the 1.1 implantation isn't managed.

Today, thanks to Nicole, I found System.Collections.Specialized.BackCompatibleStringComparer on the 2.0 CLR. This class implements the 1.1 CLR String.GetHashCode algorithm and can be found in the System.dll and System.Windows.Forms.dll assemblies. You can't use it because it's internal but you can see its implementation using Reflector. You can also see it here.

Now I have a few questions:

Published Fri, May 30 2008 0:50 by Paulo Morgado

Filed under: , , ,

Leave a Comment

(required) 
(required) 
(optional)
(required)