简体   繁体   中英

Assembly reference error (CS0234) when using System.Security.Cryptography in Xamarin Studio 6.1 on Mac OS X

Running Xamarin Studio (Community) 6.1 (build 4963) on OS X El Capitan 10.11.5, I am trying to use RNGCryptoService in my solution (targets iOS and Android) for which I need to use the namespace System.Security.Cryptography. However, it seems like using System.Security.Cryptography; and then calling RNGCryptoServiceProvider random = new RNGCryptoServiceProvider(); somewhere in my code gives me the error.

Error CS0234: The type or namespace name 'Cryptography' does not exist in the namespace 'System.Security'. Are you missing an assembly reference? (CS0234)

I tried to look for the System.Security.Cryptography package in the NuGet repositories (including the pre-release versions) but I did not find anything.

What am I missing? Where can I find the assembly reference?

You need the System.Security.Cryptography.Algorithms package to use RNGCryptoServiceProvider . Install that with NuGet v 3.4 or later:

> PM Install-Package System.Security.Cryptography.Algorithms

You may also need to modify your project.json file to make this package a dependency of dotnet5.4 and not a global dependency to stop the compiler from complaining about duplicate class declarations.

Follow up: It looks like System.Security.dll is not supported on Xamarin.iOS or Android. As an alternative, you might have some luck with Jeffrey Stedfast's fork of the Bouncy Castle cryptography library bc-csharp for use with Xamarin.Android and Xamarin.iOS.

Another option might be to use the PCLCrypto library with this helper class and workaround for NuGet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM