Missing Resources after installing ADAL Package for Xamarin.Forms PCL - c#

I am developing a Xamarin.Forms PCL mobile application and need access to an internal API that requires authentication via Azure. My coworker gave me a code snippet that works in a console application, and I am attempting to adapt it for my mobile application.
I am able to successfully add the ADAL package to the PCL. However, authentication requires that I pass along a set of PlatformParameters for each platform-specific version. When I attempt to add the ADAL package to the Xamarin.Android project, I get the following errors in my Resource.Designer.cs file:
ERROR: 'Resource.Id' does not contain a definition for 'agentWebView'
ERROR: 'Resource.Layout' does not contain a definition for 'WebAuthenticationBroker'
The relevant (auto-generated) lines of code in Resource.Designer.cs are:
global::Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.Resource.Id.agentWebView = global::MissionControlAuth.Droid.Resource.Id.agentWebView;
global::Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.Resource.Layout.WebAuthenticationBroker = global::MissionControlAuth.Droid.Resource.Layout.WebAuthenticationBroker;
The names of these missing resources suggest that I need to point the ADAL package to a webview that can be used to display a login page to the user. Unfortunately, I haven't been able to find any mention of this on StackOverflow or on the Xamarin forums. How can I correctly set up the ADAL package for my Xamarin.Forms PCL?
Platform / Library Versions
.NET Framework 4.5
Xamarin.Forms v2.0.0.6482 targeting Xamarin.Android and UWP
Visual Studio 2015
Microsoft.IdentityModel.Clients.ActiveDirectory v3.5.207081303-alpha (relevant answer)
Alternatively, Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory v4.0.209160138-alpha (relevant answer)
Steps to Reproduce
Create a new Xamarin.Forms PCL project.
Choose one of the ADAL package versions above and add it to the PCL.
Add the same package version to the Xamarin.Android project. The library will install successfully, but there will be missing resource errors in the "Error List" tab in Visual Studio.

Experimental library is not supported. Please switch to MSAL available at https://www.nuget.org/packages/Microsoft.Identity.Client

Related

Which PCL profile should I use in my Xamarin.Forms app?

I'm new in Xamarin, Xamarin.Forms and C# platform.
I'm starting the development of an app that should support Android and iOS devices. I'm using a PCL project for code sharing. Currently this project is using the profile111 because Visual Studio has selected it by default for me. But when I try to install some NuGet packages I'm getting a message saying the package is not compatible. Something like:
Could not install package 'DocsBrStandard 2.0.1'. You are trying to
install this package into a project that targets
'.NETPortable,Version=v4.5,Profile=Profile111', but the package does
not contain any assembly references or content files that are
compatible with that framework.
I believe this message is related with the profile I'm using, right?
So which profile should I use for my app that should support only iOS and Android devices? Is profile111 the more appropriate for this scenario?
At least, how can I identify if a package is compatible or not with my Xamarin.Forms app?
Thanks.
You need to target .NET Standard to be able to use the DocsBrStandard package. So you can't work with profile based PCL if you want to use that package.
Check out this article about targeting .NET Standard with Xamarin.Forms:
https://blog.xamarin.com/building-xamarin-forms-apps-net-standard/

Xamarin.Android Build Error after target sdk change

Getting the following error in my MainActivity.cs in my Android project of a Xamarin.Forms solution:
CurrentPlatform is inacessbile due to its protection level
From the following line of code which is inside the OnCreate(), with only the CurrentPlaftorm portion underlined:
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
I didn't receive this error until I upgraded my MonoAndroid to v7.0 from v6.0 and did all the necessary updates that come with that like JDK 1.8.
Wondering if someone can explain what this error means and why it is being invoke specifically for the CurrentPlatform.
I tried to recreate this error in a new project but once I typed Microsoft.WindowsAzure.MobileServices. it had the CurrentPlatform option available with no issue.
Also now a line using the MobileServiceClient type calling the LoginAsync() from the WindowsAzure component throws two errors on the parameters which used to be:
await client.LoginAsync(context, "facebook");
But I receive the following two errors now:
Argument 1: cannot convert from 'Android.Content.Context' to 'Microsoft.WindowsAzure.MobileServices.MobileServiceAuthenticationProvider'
Argument 2: cannot convert from 'string' to 'Newtonsoft.Json.Linq.JObject'
Not sure why these two areas of code broke when I changed my Android Target SDK as they were just part of the Microsoft.WindowsAzure components.
Not sure why these two areas of code broke when I changed my Android Target SDK as they were just part of the Microsoft.WindowsAzure components.
According to your description, I assumed that it dues to the version of Azure Mobile Client SDK you referenced.
For Azure Mobile Client SDK 3.1.0, you client would reference the lib from the following path:
Microsoft.Azure.Mobile.Client.3.1.0\lib\monoandroid\Microsoft.WindowsAzure.Mobile.Ext.dll
You could leverage ILSpy to check the extension methods for LoginAsync as follows:
While for Azure Mobile Client SDK 4.0.0-alpha-001, if your MonoAndroid >= 4.4, then the lib would be reference under:
Microsoft.Azure.Mobile.Client.4.0.0-alpha-001\lib\monoandroid44\Microsoft.Azure.Mobile.Client.dll
For Azure Mobile Client SDK 4.0.0, if your MonoAndroid >= 7.1, then the lib would be reference under:
Microsoft.Azure.Mobile.Client\4.0.0\lib\monoandroid71\Microsoft.Azure.Mobile.Client.dll
My previous project targets on Android 6.0, then the lib would only reference Microsoft.Azure.Mobile.Client.4.0.0\lib\netstandard1.4\Microsoft.Azure.Mobile.Client.dll, and there has no extension methods for LoginAsync via server-flow authentication.
In summary, from your code await client.LoginAsync(context, "facebook");, you are using Server-managed authentication, I would recommend that you could use Azure Mobile Client SDK 3.1.0 without upgrading your Android SDK version or use the latest Azure Mobile Client SDK 4.0.0 and upgrading your Android SDK version to 7.1 or higher.
Additionally, the code client.LoginAsync(MobileServiceAuthenticationProvider.Facebo‌​ok,{JObject token}) is using Client-managed authentication, at this point, your app can independently contact the identity provider and then provide the returned token during login with your azure mobile backend.

Cannot add the Signalr Client library as a portable library to a Xamarin project

I have tried adding the Signalr Client library and the WebApi client package to my Xamarin Solution (on Visual Studio with Xamarin Support and also on Xamarin Studio) but I always get this error although I am able to install other PCLs (for example Microsoft.Net.Http):
Could not install package 'Microsoft.AspNet.WebApi.Client 5.2.3'. You are trying to install this package into a project that targets 'portable-net45+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10', 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.
and the following error when adding Signalr:
Adding Microsoft.AspNet.SignalR.Client...
Adding 'Microsoft.AspNet.SignalR.Client 2.2.0' to Corda.Client.
Could not install package 'Microsoft.AspNet.SignalR.Client 2.2.0'. You are trying to install this package into a project that targets 'portable-net45+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10', 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 have also tried changing the the target framework with not success.
This is the build setting for my project:
and this is my C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile259\SupportedFrameworks folder:
I get the same errors on both Mac OSX and Windows 10. Any ideas?
Using Profile78 solved my problem. Full explaination here.
A simple workaround that worked with my Xamarin with VS:
Download the dll-files manually here: https://components.xamarin.com/gettingstarted/signalr/true
Import the following into your solution.
Microsoft.AspNet.SignalR.Client.dll
Newtonsoft.Json.dll
System.Net.Http.Extensions.dll
System.Net.Http.Primitives.dll
Done!
The problem is not with the dll-files, but with the (nuget) installer.
The problem is with the nuget package manager,specifically with the Windows Phone 8.1 project. I think it expects it to be a windows phone silverlight 8.1 project. There is a bug on installing signalr client on an universal 8.1 phone project in a xamarin project. It should be sorted out in the next xamarin release. Unselecting windows phone 8.1 in the portable config solves the issue,meaning you will have to take the windows phone 8.1 project out of the xamarin project and your need to create a universal windows 10 project.
Yes, As suggested by others this is the problem from nuget package manager, As per this link it should be fixed with the realease of Microsoft.signalr.client 2.2.1 version but for now if you still want to go with nuget, Add the below nuget source
https://www.myget.org/F/aspnetwebstacknightly/
to visual studio and install pre release version 2.2.1 pre-160523-b816 of the signalr client dll as suggested in below link
https://github.com/SignalR/SignalR/issues/3393

MvvmCross-SecureStorage in PCL

I'm trying to add MvvmCross-SecureStorage plugin of MvvmCross to PCL wich contains classes shared between Universal Widows app iOs apps and Android apps, but I'm getting this kind of error.
Could not install package 'Beezy.MvvmCross.Plugins.SecureStorage 1.0.0'. You are trying to install this package into a project that targets 'portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10', 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.
Anybody successfully added this plugin to PCL?
Looking at https://github.com/ChristianRuiz/MvvmCross-SecureStorage it looks like this project doesn't yet support the new unified xamarinios10 target which is included in your list.
One route forwards would be to add unified support to that open source project and to send them a Pull Request.

Xamarin.Forms could not install package

When creating a new solution within Xamarian studio I get this error
Could not install package 'Xamarin.Forms 1.0.6186'. You are trying to install this package into a project that targets '.NETFramework,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.
Is there a certain version of .Net that Xamarian Forms requires for it to be included in the solution? I've tried searching in their documentation but I'm only seeing marketing and not real in depth documentation.
I had a similar issue using Visual Studio and I've found that the following combination in the PCL works:
.NET Framework 4.5
Windows Phone Silverlight 8
Xamarin.Android
Xamarin.iOS
You have created the wrong project type, you created a normal Windows app, and I assume you are targeting iOS/Android or Mac.
Create the project with the correct type and it should work correctly.
If you are using Xamarin Studio for Windows (without also having Visual Studio installed) you need to download the Portable Library Tools. See the Xamarin doc Introduction to Portable Class Libraries.
I had the same problem with my Xamarin project. The problem was, that in the portable Xamarin project Windows Phone Silverlight was set as target. The PCL project from which I created the nuget, didn't reference Silverlight as target. I don't need Silverlight, so uninstalling all nuget packages from my portable Xamarin project, removing silverlight as target and reinstalling the NuGet packages solved it.
I had similar issue using VS and I found solution here - http://forums.xamarin.com/discussion/29674/xamarin-forms-dll-cannot-be-installed
"It looks like your NuGet Package Manager needs to be upgraded. The Xamarin PCL Profiles are installed but NuGet is not recognising Xamarin.iOS as a target framework. You can update NuGet by selecting Tools - Extensions and Updates, then select the Updates tab, then select Visual Studio Gallery. Then update NuGet from there."
I have invested a lot of time trying all the solutions posted here, but none of them helped me... Here is the solution that worked for me (on Windows 10):
1.) Open your .csproj file
2.) Find the TargetFrameworkProfile entry
3.) This entry contains Profile78 for me, therefore I open the folder below
c:/Program Files (x86)/Reference Assemblies/Microsoft/Framework/.NETPortable/v4.5/Profile/Profile78/SupportedFrameworks
4.a) If the folder does not exist, then use one of the solutions posted here to install the PLC right on your PC
4.b) Unfortunately, ASP.NET and Xamarin don't like each other, therefore delete all ASP profiles from this folder. For me it was ASP.NET Core 5.0.xml. Obviously this will break your ASP.NET support in VS
5.) Restart Xamarin and have fun!
interesting reading about all that:
https://forums.xamarin.com/discussion/52846/cannot-create-new-xamarin-forms-project-pcl-in-xamarin-studio-win10-vs2015

Categories

Resources