SingalR in Xamarin.Forms - c#

I'm trying to create a Xamarin.Forms PCL client for SignalR. Every tutorial I found it's how to add SignalR to either Xamarin.Android or Xamarin.iOS. How can I add SignalR to Xamarin.Forms project?
Should I create an separate PCL, call it "Proxy" and then just use this PCL in Xamarin.iOS, Android and Windows Mobile projects?
If 1), should I add SignalR also in every project (besides PCL, where I'm really using it)?
Should I add to the PCL created by default, while creating Xamarin.Forms solution?
Thanks for help,
Here's the problem I'm getting:
I have a fully working Xamarin.Forms PCL project. I removed all windows stuff though. I just left PCL, iOS and Android projects. It works! I added CocosSharp only, but don't use it. Plain, empty, never touched Xamarin.Forms. Then I've added SingalR to PCL project. Complied, run - works! BUT when I add JUST this line:
var connection = new HubConnection("http://localhost:52128");
it doesn't even compile. I'm getting errors:
Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Perhaps it doesn't exist in the Mono for Android profile
I'm totally lost.
I've tried:
Installing nuget just on the PCL - error
Installing on every project - error
Creating new PCL, implementing that line there, adding it as a reference to the main PCL. Calling a method from the second PCL - error.

I met the same error as you did, it seems that when installing SignalRMicrosoft.AspNet.SignalR.Client package, the dependency packages cannot be automatically installed, the references got somehow corrupted.
To solve this issue, you can manually install those packages.
Install the following three Packages separately from Nuget:
SignalRMicrosoft.AspNet.SignalR.Client.
Newtonsoft.Json.
Microsoft.Net.Http.

Related

c# function app: This functionality is not implemented in the portable version of this assembly ( But I only have one project, no portable)

I am building my first function app.
I use a nuget package which I used a lot before in my xamarin.forms apps. Now, when I init the package I am getting:
This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
But I am using this in my main project. There are no sub projects, no PCL, or anything xamarin related.
What is it that I am doing wrong?
It appear on this line of code:
var config = Kumulos.CurrentConfig.AddKeys(
"asd",
"123");
Kumulos.Current.Initialize(config);
}
Whic h is the first time I even reference the nuget package at all...

Creating Xamarin.Forms .Net Standard app with Azure IOT Library?

I'm making an iOS/Android app that will work with Azure IoT Hub. The latest Microsoft.Azure.Devices version from what I understand is only compatible with .Net Standard projects. I've been trying to follow these twho tutorials (1, 2) to convert PCL project to .Net Standard project to no avail, and I'm lost on what I'm doing wrong.
These are the steps that I'm taking.
Create new Cross Platform App called TestProject. Xamarin.Forms -> Blank App -> Portable Class Library (PCL)
Right click solution -> Add New Project -> .Net Standard -> Create .Net Standard Library called TestProject.Core
Delete the auto generated class Class1.cs and move App.xaml and MainPage.xaml to TestProject.Core.
Delete Portable Library TestProject.
Rename TestProject.Core to TestProject.
Add TestProject reference to iOS and Android.
Click on TestProject and select Edit TestProject.csproj. Change PropertyGroup to following:
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8
</PropertyGroup>
Right click on solution and select Manage Nuget Packages For Solution.
Check Include Prerelease and install 2.3.5.256-pre6 Xamarin.Forms on TestProject, TestProject.Droid and TestProject.iOS.
Clean and Rebuild solution.
Right click on TestProject and select Manage Nuget Packages. Install Microsft.Azure.Devices
Clean and Rebuild.
Add code to TestProject that uses Microsoft.Azure.Devices.
Rebuild and get error:
Project File Line Suppression State Error Exception while loading assemblies: System.IO.FileNotFoundException:
Could not load assembly 'Microsoft.Azure.Devices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Perhaps it doesn't exist in the Mono for Android profile? File name: 'Microsoft.Azure.Devices.dll'
From what I can understand I am missing Microsoft.Azure.Devices Nuget package on
TestProject.Droid, however, when I attempt to install it, I get the following error:
Could not install package 'System.Threading.Overlapped 4.3.0'.
You are trying to install this package into a project that targets
'MonoAndroid,Version=v7.1', but the package does not contain any assembly references or
content files that are compatible with that framework.
When I try to install *Microsoft.Azure.Devices** on iOS:
Could not install package 'System.Threading.Overlapped 4.3.0'. 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.
I'm making an iOS/Android app that will work with Azure IoT Hub. The latest Microsoft.Azure.Devices version from what I understand is only compatible with .Net Standard projects.
Per my understanding, you could leverage the Azure IoT Hub client SDK portable library Microsoft.Azure.Devices.Client.PCL which supports Android, iOS, Windows 10 (UWP) and Windows Phone (WinRT). Also, here is a sample uses Microsoft.Azure.Devices.Client.PCL, you could follow here.

Xamarin.Auth Android project results in "Cannot find symbol" error for CustomTabs?

I am trying to implement the Xamarin.Auth library in a Xamarin.Forms project. After installing the library in my client project I received a System.NotImplementedException:
System.NotImplementedException:
Portable Bait And Switch is nuget feature, so the package must be installed in all project.
NotImplementedException will indicate that Portable Code from PCL is used and not Platform Specific implementation.
Please check whether platform specific Assembly is properly installed.
Therefore, I installed the library in the Droid project as well. Once I did this, I started getting "Cannot find symbol" errors related to the CustomTabs control:
error: cannot find symbol
extends android.support.customtabs.CustomTabsCallback
symbol: class CustomTabsCallback
location: package android.support.customtabs Kpa.Mko.Mobile.Client.Droid
H:\...\obj\Debug\android\src\android\support\customtabs\CustomTabsClient_CustomTabsCallbackImpl.java
There are 6 of these errors in all, each one related to CustomTabs in some way.
We're using:
Xamarin.Auth 1.3.2.5 Xamarin.Forms 2.3.3.193
Xamarin.Android.Support.v7.AppCompat 25.1.1
Xamarin.Android.Support.v7.CardView 25.1.1
Xamarin.Android.Support.v7.MediaRouter 25.1.1
Xamarin.Android.Support.v7.RecyclerView 25.1.1
I've done some research on this problem in the Xamarin forums, here on Stack Overflow, and of course Google but none of the suggested fixes I found is solving my problem. I am completely confused as to what could be going on here. Am I missing the obvious?
Thanks!
Make sure you have the Xamarin.Android.Support.CustomTabs NuGet package installed. This is not, by default, included in the pre-packaged Xamarin.Android.Support packages that are loaded with the Android project template.
Nuget package tuning can be problematic. I had numerous problems since I added Xamarin.Forms support. Try nuking all bin/ and obj/ folders, if not update SDK and then again nuke everything...
Xamarin.Auth nuget has dependencies and it should pull other stuff in.
Samples extracted from the repo:
https://github.com/moljac/Xamarin.Auth.Samples.NugetReferences

Missing Resources after installing ADAL Package for Xamarin.Forms PCL

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

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.

Categories

Resources