Weird ASP.NET AJAX Bug / 32-bit to 64-bit

别来无恙 提交于 2019-12-03 15:17:25

It looks like the String.GetHashCode() result changes based on what instruction set the dll has been compiled for. I can't explain why this happens within the framework when your .NET 2.0+ app pools are all 64-bit but there's a solution you can try if you're willing to grab the latest source off codeplex and change a few lines in the ToolkitScriptManager.

I don't know why an official fix hasn't been submitted based on the comments available--maybe because all the solutions are as ugly as mine?

I've attempted to fix it by using the SHA1 hash routine as described in one of the comments--so first I created a static instance of the SHA1Managed provider in the ToolkitScriptManager class as shown below:

public class ToolkitScriptManager : ScriptManager
{
    private static System.Security.Cryptography.SHA1Managed s = new System.Security.Cryptography.SHA1Managed();

...

then there are two places where the string hash code was being used that I commented out and replaced--once in the SerializeScriptEntries function:

//serializedScriptEntries.Append(scriptEntry.Name.GetHashCode().ToString("x", CultureInfo.InvariantCulture));
serializedScriptEntries.Append(Convert.ToBase64String(s.ComputeHash(System.Text.Encoding.UTF8.GetBytes(scriptEntry.Name))));

and then once in the DeserializeScriptEntries function:

//string hashCode = resourceName.GetHashCode().ToString("x", CultureInfo.InvariantCulture);
string hashCode = Convert.ToBase64String(s.ComputeHash(System.Text.Encoding.UTF8.GetBytes(resourceName)));

Maybe a simpler method would allow us to just access the 64-bit GetHashCode method for serializing this string so that we get the same results for 32-bit and 64-bit calls...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!