4

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.

Ish Thomas
  • 2,270
  • 2
  • 27
  • 57
  • https://www.nuget.org/packages/Microsoft.AspNet.SignalR.Client/ What's the error you got when using this package? – Lex Li Feb 05 '17 at 04:33
  • @LexLi thanks for a response. Look at my updated question please – Ish Thomas Feb 05 '17 at 06:18
  • you should google how to do assembly redirection in Xamarin.iOS and Xamarin.Android entry project to map to the correct JSON.NET version. The referenced version in NuGet package (aka 6.0) was too old. – Lex Li Feb 05 '17 at 07:39
  • @LexLi I'm not sure I understood. Does that mean, that singalR package on nuget installs old version of JSON.NET? That this is a bug in the nuget package? – Ish Thomas Feb 05 '17 at 18:24

1 Answers1

5

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.

Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • Interesting, who's fault is that? SignalR, Xamarin and Visual Studio are all supported by Microsoft and I saw that problem (and this very solution) in posts around 2 years ago. How is it possible that they didn't fix it? I'm asking because I'm not sure, maybe I did something wrong. – Ish Thomas Feb 07 '17 at 02:24
  • About the solution... It looks better, it compiles, but I'm not sure if the problem was solved. I can't connect to the server though. Now I'm not sure if this is because of the "localhost" and not a real server? – Ish Thomas Feb 07 '17 at 02:25
  • @IshThomas, I saw some [discussions about this issue](https://forums.xamarin.com/discussion/36281/system-net-http-extensions-cannot-be-found-although-it-is-not-used), this solution should solve the problem, though I don't understand why your connection failed. – Grace Feng Feb 07 '17 at 02:31
  • Because it's a different question, I posted it here: http://stackoverflow.com/questions/42080473/how-to-connect-to-signalr-server-from-xamarin-client – Ish Thomas Feb 07 '17 at 03:05
  • @IshThomas, I'm not familiar with SignalR, your this question is about how to use this package in Xamarin, I think the solution is delivered already, you did the right thing to open a new thread to discuss the connection issue, but I don't think it is much related to this thread. – Grace Feng Feb 07 '17 at 03:08
  • Yes, I just thought that you might know. Anyway, thanks for help! – Ish Thomas Feb 07 '17 at 03:51