I'm trying to use System.Security.Cryptography.RNGCryptoServiceProvider class in my .NET Standard 1.4 library and according to this topic my code looks like this:
private byte[] GenerateRandomNumber(int length)
{
using (var randomNumberGenerator = RandomNumberGenerator.Create())
{
var number = new byte[length];
randomNumberGenerator.GetBytes(number);
return number;
}
}
I have also installed from NuGet libraries:
- System.Security.Cryptography.Algorithms v=4.3.0
- System.Security.Cryptography.Primitives v=4.3.0
But trying fire it up gives me:
'Could not load file or package' System.Security.Cryptography.Algorithms, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a 'or one of its dependencies. The specified file could not be found. '
And on NuGet page there is no 4.1.0.0 version, only 4.1.0-rc2-24027 and after installing this version I get exact same exception.
What is wrong?
Edit: Switching from .NET Standard 1.4 to 1.6 didn't help
Edit2:
When I hit F12 on RandomNumberGenerator
:
#region Assembly System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// C:\Users\x.y\.nuget\packages\system.security.cryptography.algorithms\4.3.0\ref\netstandard1.4\System.Security.Cryptography.Algorithms.dll
#endregion
namespace System.Security.Cryptography
{
public abstract class RandomNumberGenerator : IDisposable
{
protected RandomNumberGenerator();
public static RandomNumberGenerator Create();
public void Dispose();
public abstract void GetBytes(byte[] data);
protected virtual void Dispose(bool disposing);
}
}
So it wants 4.1.0 version (that not exists on NuGet) but path is set for 4.3.0
System.IO (>= 4.3.0)
,System.Runtime (>= 4.3.0)
,System.Security.Cryptography.Primitives (>= 4.3.0)
– Lexicologistapp.config
redirecting the desired version to the actual version. – Manes