I have following code written in application.
var salt = "0115ee62e6e5e8ea68db9e2d7e72cec85e810ad9566212ffc2c4b76a17ca0b00";
var hashCode = StringComparer.OrdinalIgnoreCase.GetHashCode(salt ?? string.Empty);
It has different behaviour in 'asp.net core' and 'standard' framework.
Framework 4.7: If I will use this code in website/console application created in standard framework of .net, it alwasy give me same result. The value of hashcode variable is always "1066337973".
Asp.net Core: If I will use this code in asp.net core website, then every time I stop the application and start again, the hashcode variable have differnt value.
Becasue of this problem, my logic is getting failed in asp.net core application.
How this problem can be solved?
GetHashCodeimplementation was changed in .NET Core, it's an expected behavior, have a look at this article Why is string.GetHashCode() different each time I run my program in .NET Core?GetHashCodetells you do not persist hash value and do not use the hash code instead of a value returned by a cryptographic hashing functionString.GetHashCodeHash codes for identical strings can differ across .NET implementations, across .NET versions, and across .NET platforms (such as 32-bit and 64-bit) for a single version of .NET. In some cases, they can even differ by application domain. This implies that two subsequent runs of the same program may return different hash codes.