Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you generate an x86 hash value when running in x64 mode?

Tags:

c#

c#-4.0

I was bit this week by a bug that occurred when my code was hosted in an x64 process. I am using a hash value for lookup and I am storing that hash value in a database. The hash value that has been generated in the past was a x86 hash and now that x64 hashes are being generated I am getting errors because the lookup values don't match anymore.

I am highly skeptical of this, but I thought I'd ask anyway. Is there a way to generate an x86 hash value if my code is running in an x64 process?

For reference, I am running on .NET 4.0 using C#.

Edit:

Here's the problem I've been running into: String.GetHashCode() returns different values

You can duplicate the problem by creating a console app with the following code:

"DDD.Events.Application.ApplicationReferenceCreated".GetHashCode()

Run the app with x86 platform, then run it with the x64 platform.

I just want to get consistent values across platforms. However, I may just create a pre-compiled list of hashes so I can fail over in the event I need to. I just wanted to know if there were a way to get consistent values from GetHashCode(). I don't think so, but if it is possible it would be the easiest solution in my case.

like image 590
Mark J Miller Avatar asked Dec 17 '10 16:12

Mark J Miller


1 Answers

I'm afraid if you are using the default implementation in .NET then this is not possible. They do not even guarantee it will return the same id between different versions of .NET; and explicitly state it must not be used as a unique identifier. Have a read of this on MSDN

like image 144
Bigtoe Avatar answered Sep 30 '22 05:09

Bigtoe