Could not install package 'System.Security.SecureString' - c#

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 !

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.

Related

nuget not resolving dependency using what specified in nuget package for Microsoft.Extensions.Logging

Background:
I have created a class library for .net core (targetting v2.2), and I have a .net core application as well (targetting v2.2).
I am trying to export the library as nuget package and install it in my application.
Here is the dependencies for my library
I am able to export it as nuget package and for now I am storing it in local nuget repo.
But when I try to install this library package in my application it's not getting installed due to package version conflict for Microsoft.Extensions.Logging. Here's package manager console output.
Issue:
I have specified the exact version for Microsoft.Extensions.Logging i.e. [2.2.0] as we could confirm that in the screenshot showing dependency for my library, then why it's getting resolved to version 3.0.0?
How could I resolve this issue?
Details about the environment:
NuGet product used (Package Manager Console): Package Manager Console Host Version 5.3.1.6268
VS version (if appropriate): Microsoft Visual Studio Community 2019 Version 16.3.8
OS version (i.e. win10 v1607 (14393.321)): Windows 10 Enterprise Version: 1809
How could I resolve this issue?
To resolve the strange behavior in your side, you should clean the nuget cache before installing that package in your current project.
(To make sure the cache is cleaned up, I suggest you go %userprofile%\.nuget\packages to check if there exists Com.lib folder within the Packages folder)
I have specified the exact version for Microsoft.Extensions.Logging
i.e. [2.2.0] as we could confirm that in the screenshot showing
dependency for my library, then why it's getting resolved to version
3.0.0?
I think the one(Com.Mylib) you want to install is not the first one you pack. I mean that you may actually build and pack several different Com.Mylib package with different content. And all of their names is Com.lib.1.0.0.nupkg.
Nuget stores all nuget cache in %userprofile%\.nuget\packages. So if I once install one PackageA in any project. The cache of PackageA is stored there. And if I open a new project trying to install the PackageA with same version(1.0.0), it actually installs the one from cache. So we will meet this strange behavior:
Nuget can recognize the Com.lib package depends on other 2.2.0 packages. But when it tries to install that package, it finds the package has existed in cache. Then he tries to install the one from cache, and I guess content of the one in cache is different from your latest one, then the issue occurs.
Suggestions:
1.When developing locally, use project reference instead of Nuget packages.
2.If you need to test the nuget package every time after packing, please make sure the package version has increased.(1.0.0=>1.0.1=>1.0.3... or beta-1.0.12, preview-xxx)
3.If you have special reason do use same version 1.0.0, please clean the cache to avoid previous cache affects current project.
Hope all above helps :)

Cannot update nuget package (PCL)

I'm getting this error when using maps in Android:
System.MissingMethodEsception: Method
'Xamarin.Forms.maps.Android.MapRenderer.OnCameraChange' not found.
And I've read that you can update the nugetpackage to fix the issue. However, I cannot install it due to this:
Could not install package 'TK.CustomMap 2.0.1'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile78', 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.
The updates of packages installs just find in iOS and Android but not for PCL. I've tried to remove all the packages and then tried to add TK.Customs nuget package but this same issue.
Also tried to install it on a fresh project and that installed just fine. Just cant get it to install on my old project.
Here is the whole error message when trying to update package:
Attempting to gather dependency information for package 'TK.CustomMap.2.0.1' with respect to project 'Vernamo', targeting '.NETPortable,Version=v4.5,Profile=Profile78'
GET https://api.nuget.org/v3/registration3-gz-semver2/tk.custommap/index.json
OK https://api.nuget.org/v3/registration3-gz-semver2/tk.custommap/index.json 175ms
Total number of results gathered : 29
Gathering dependency information took 232 ms
Summary of time taken to gather dependencies per source :
https://api.nuget.org/v3/index.json - 204.03 ms
Attempting to resolve dependencies for package 'TK.CustomMap.2.0.1' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'TK.CustomMap.2.0.1'
Resolved actions to install package 'TK.CustomMap.2.0.1'
Found package 'TK.CustomMap 2.0.1' in '/Users/holger/Downloads/Vernamo/packages'.
For adding package 'TK.CustomMap.2.0.1' to project 'Vernamo' that targets 'portable45-net45+win8+wp8'.
Install failed. Rolling back...
Package 'TK.CustomMap.2.0.1' does not exist in project 'Vernamo'
Executing nuget actions took 52 ms
Could not install package 'TK.CustomMap 2.0.1'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile78', 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.
The pre-release version (at least pre2) of TK.CustomMap supported all platforms (see here), anyway, as of pre3 (see here), obviously the support for all platforms was dropped in favor of .NET Standard (1.1 in this case).
The profile you are using in your PCL does not seem to be compatible with .NET Standard 1.1, hence NuGet fails to add the reference. You may try to switch to another profile (.NET 4.5.1 for example), but I don't know if that would help. Another option would be to migrate your projects to .NET Standard. It's kind of a stupid, repetetive task, but it's possible.

I Cant Install Microsoft.Identity.Client In Xamarin.Forms

I Try to Install Microsoft.Identity.Client Nuget to my Xamarin.Forms Project. But every time i try to install the package I always get this error message:
Could Not install package ' Microsoft.Identity.Client 1.0341221-alpha'. 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 iformation, conct the package author
What should I do here, I have already tried all version of the package, and try to install the package from Package Manager Console
The error is very clear, the NuGet does not contain any target platforms that are supported in your PCL profile 259.
You should migrate your PCL to a .NET Standard library, at least version 1.1 to consume the NuGet package in your shared code. Alternatively, you could abstract it away with an Interface and Dependency Injection, which probably will be more time consuming.

Can't install Microsoft.ProjectOxford.Face NuGet into Xamarin Studio iOS project

I tried a lot, but I can't install Microsoft.ProjectOxford.Face NuGet into Xamarin Studio iOS project.
I got this error:
Could not install package 'Microsoft.ProjectOxford.Face 1.2.5.1'. You are trying to install this package into a project that targets 'Xamarin.iOS,Version=v1.0', 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.
I tried to update all packages, also Xamarin and still same problem. Only this package does not work - other like Newtonsoft.Json, Mircosoft.Net.HTTP and many other was installed correctly. I tried to install first Microsoft.BCL also Microsoft.BCL.Build and it also does not work.
Maybe you have any thoughts what can I do to make it work?
Unfortunately this is a problem with the Microsoft.ProjectOxford.Face 1.2.5.1 NuGet package itself. Whilst it has a portable class library (PCL) folder this does not map to a valid PCL profile:
portable-net45+wp80+win8+wpa81+aspnetcore50
If the aspnetcore50 part of that folder is removed then it would install into Xamarin.iOS. As it is, NuGet will not allow you to install it.
The only thing left you can do is unzip the NuGet package and try directly using the assembly. NuGet will not allow you to install it.
I believe there are plans to update the NuGet package to fix this, but that has not yet happened.

How to add nuget package in Xamarin studio

I am completely new to xamarin studio. I am trying to add a nuget package. using the add packages dialogue appears to be working however I get an error:
Attempting to gather dependency information for package 'SidebarNavigation.1.9.0.3' with respect to project 'helloios', targeting '.NETPortable,Version=v4.0,Profile=Profile344'
Attempting to resolve dependencies for package 'SidebarNavigation.1.9.0.3' with DependencyBehavior 'Lowest'
Resolving actions to install package 'SidebarNavigation.1.9.0.3'
Resolved actions to install package 'SidebarNavigation.1.9.0.3'
For adding package 'SidebarNavigation.1.9.0.3' to project 'helloios' that targets 'portable40-net45+sl5+win8+wp8+wpa81'.
Install failed. Rolling back...
Package 'SidebarNavigation.1.9.0.3' does not exist in project 'helloios'
Package 'SidebarNavigation.1.9.0.3' does not exist in folder '/Users/********/Projects/helloios/packages'
Could not install package 'SidebarNavigation 1.9.0.3'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.0,Profile=Profile344', 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.
This is the github page for the package.
https://github.com/jdehlin/Xamarin-Sidebar
I tried to use different PCL profiles to no effect. I'm not sure how to determine which profile should be used.
The package targets only "Xamarin.iOS". You can't reference it in a PCL that targets more than that, since any other platform wouldn't be able to use it.
Either don't use a PCL, or restrict the PCL to "Xamarin.iOS".
Since this seems to be a UI component, you should reference it from your main project instead, and maybe expose some functionality through services to the PCL, if needed.

Categories