Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are HashTable order different in Visual Studio Debugging compared to IIS

Tags:

c#

hashtable

I have a very curious thing happening in my application with HashTables.

First off: Yes, I know that HashTables are not supposed to be ordered in the way the were inserted, or any other way (but the hashes of the keys). That doesn't answer my question. I do not need it ordered, I just want to know WHY it differs between two seemingly identical systems.

So, here it is. Left side is IIS ordering, right side is Visual Studio.

IIS vs VS ordering in HashTable

Why is it different? Considering that .NET should (?) use the same algorithm to store, and retreive, data from a HashTable, the ordering should be the same on both sides, shouldn't it?

If, as I learned it, the key of a HashTable is hashed, then this hash should be the same on both systems, resulting in the same order of hashes (keys) and therefore the same order of data in the hashtable.

Where am I wrong? What difference is there in the HashTable implementation between IIS and VS?

A few extra notes from comments:

  • Project is targeted at .NET 4.0
  • IIS uses .NET 4.0 for the Application Pool
  • I actually copied the compiled binaries from Visual Studios bin folder to the IIS folder, so they are exactly the same
  • My assumption is that IIS uses the same .NET implementation as Visual Studio. If not: Why? And what makes the hashing on IIS so different from the one in Visual Studio?
like image 682
F.P Avatar asked Jan 16 '15 12:01

F.P


1 Answers

In order for items in the table to have the same ordering several conditions must be met:

  1. Hash algorithm must be the same. This means not only the hash function, but also the way the table grows, shrinks, handles collision, and so on. This is probably the reason in your case (different algorithms).
  2. Environment must be the same. Makes sense if one of the parameters of hash algorithm is something from the environment, like available memory. Some algorithms are pretty sophisticated, trying to avoid page misses or spicing the table for security purposes.
  3. Data must be the same, and stored in hash table in the same order.
like image 101
Dialecticus Avatar answered Nov 05 '22 05:11

Dialecticus