开发者

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

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 s开发者_Python百科toring 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜