简体   繁体   中英

SingalR in Xamarin.Forms

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?

  1. Should I create an separate PCL, call it "Proxy" and then just use this PCL in Xamarin.iOS, Android and Windows Mobile projects?
  2. If 1), should I add SignalR also in every project (besides PCL, where I'm really using it)?
  3. 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:

  1. Installing nuget just on the PCL - error

  2. Installing on every project - error

  3. 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 .

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