1
votes

I couldn't install package 'System.Security.SecureString' in my PCL.

I tried some of the solutions online such as adding project.json to the PCL but nothing works

Here is the error log

Attempting to gather dependency information for package 'System.Security.SecureString.4.3.0' with respect to project 'TestProj', targeting '.NETPortable,Version=v4.5,Profile=Profile259'
GET https://api.nuget.org/v3/registration1-gz/system.security.securestring/index.json OK https://api.nuget.org/v3/registration1-gz/system.security.securestring/index.json 144ms Total number of results gathered : 15 Gathering dependency information took 496.15 ms Summary of time taken to gather dependencies per source : https://api.nuget.org/v3/index.json - 172.87 ms Attempting to resolve dependencies for package 'System.Security.SecureString.4.3.0' with DependencyBehavior 'Lowest' Resolving dependency information took 0 ms Resolving actions to install package 'System.Security.SecureString.4.3.0' Resolved actions to install package 'System.Security.SecureString.4.3.0' Retrieving package 'System.Security.SecureString 4.3.0' from 'nuget.org'. For adding package 'System.Security.SecureString.4.3.0' to project 'TestProj' that targets 'portable45-net45+win8+wp8+wpa81'. Install failed. Rolling back... Package 'System.Security.SecureString.4.3.0' does not exist in project 'TestProj' Package 'System.Security.SecureString.4.3.0' does not exist in folder '/Users/durai/Documents/BTFleet/BT Fleet/_git/DailyCheckApp/packages' Executing nuget actions took 136.1 ms Could not install package 'System.Security.SecureString 4.3.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Any help in successfully installing the package is appreciated !

1
If you upgrade your PCL to a dotnet standard library, it should install just fine as long as its >= 1.3. Also it would include a PCL shim to support existing PCL libraries.Jon Douglas
@JonDouglas - If I convert PCL to a dotnet standard library ,then it might break MVVMlight based loosely coupled integration ? basically this PCL has viewmodels that is being used by iOS,Android and WindowsDurai Amuthan.H
Funny enough, a very similar question was asked just a few hours ago here on StackOverflow. I gave a comprehensive answer here on how you could solve this issue, sticking with PCL. Please let me know if my approach works for you.Anders Gustafsson

1 Answers

0
votes

The System.Security API of .NET is not PCL friendly and therefore cannot be added in the PCL project.

But, it can be added in the other projects of the Xamarin solution - you can add that to the native projects like Android and iOS projects. And because you can add it there you can create the implementations on those projects and call those implementation via Dependency Service in your PCL.

The high level steps are:

1.) Create an interface in your PCL.

2.) Create a method in that interface that will be implemented in the Android or iOS projects.

3.) Add the Nuget package for System.Security.SecureString to your native project.

4.) Create a class in your native code that will implement that interface from the PCL.

5.) Call this code from your PCL via DependencyService.

For an example on how to do this, see this link.

It is lengthy and tedious but worth it.