Archive for February, 2009

GetHashCode() on a 32-bit vs a 64-bit platform

Friday, February 20th, 2009

If you compile your .NET application with the standard “Any CPU” option, it will run as a 32-bit process on a 32-bit OS and as a 64-bit process on a 64-bis process.

When you use GetHashCode() the generated hashes on the 32-bit platform will differ from the hashes on the 64-bit platform…

The solution is either to not use the GetHashCode() the way you do it, or if you can’t change the way your program works you can run it in 32-bit mode by setting the 32-bit flag in the executable’s headers using CorFlags.exe.

Set the 32-bit flag:CorFlags.exe YourApplication.exe /32BIT+

Remove the 32-bit flag:CorFlags.exe YourApplication.exe /32BIT-

More info about CoreFlags.exe on MSDN: http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx

GetHashCode() in .NET 1.1 vs .NET 2.0

Thursday, February 19th, 2009

notepadd

When migrating GarageTV from .NET 1.1 to .NET 3.5 I ran in a “strange” problem.

It seems that there is a SearchBarrel table containing the links between keywords and posts (and some other info like keyword weight etc), so when a search is made you simply do a select using this table.

But… the keyword is hashed using String.GetHashCode() and that’s stored in the DB. Not clever it seems, because the GetHashCode() in .NET 2.0+ differs from the .NET 1.1 version.

Quote from MSDN: Prior to the .NET Framework version 2.0, the hash code provider was based on the System.Collections.IHashCodeProvider interface. Starting with version 2.0, the hash code provider is based on the System.Collections.IEqualityComparer interface.”

And for your information I’ve found an implementation of the GetHashCode() of the .NET 1.1 version, so you can use this method in .NET 2.0 projects.


Int32 HashString(String szStr)
{
ulong hash = 5381;

foreach (int ch in szStr)
{
hash = ((hash << 5) + hash) ^ (ulong)ch;
}

return (Int32)hash;
}

So… enjoy.

Moonlight 1.0 released: brings Silverlight to Linux

Thursday, February 12th, 2009

You can download the Mozilla Firefox plugin at the official Moonlight website. Enjoy!