Xamarin.Forms中的SingalR [英] SingalR in Xamarin.Forms

查看:99
本文介绍了Xamarin.Forms中的SingalR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为SignalR创建Xamarin.Forms PCL客户端.我发现的每个教程都是将SignalR添加到Xamarin.Android或Xamarin.iOS的方法.如何将SignalR添加到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. 我应该创建一个单独的PCL,将其称为代理",然后在Xamarin.iOS,Android和Windows Mobile项目中使用该PCL吗?
  2. 如果为1),我是否还应该在每个项目中添加SignalR(除了PCL,我确实在使用它)?
  3. 创建Xamarin.Forms解决方案时,我应该添加到默认创建的PCL吗?

感谢您的帮助,

这是我遇到的问题: 我有一个可以正常工作的Xamarin.Forms PCL项目.我删除了所有Windows内容.我刚刚离开了PCL,iOS和Android项目.有用!我仅添加了CocosSharp,但不使用它.普通,空虚,从未触及的Xamarin.Forms.然后,我将SingalR添加到PCL项目中.已编译,运行-有效!但是,当我添加此行时:

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:

加载程序集时发生异常:System.IO.FileNotFoundException:无法加载程序集"Newtonsoft.Json,版本= 6.0.0.0,区域性=中性,PublicKeyToken = 30ad4fe6b2a6aeed".也许在Mono for Android配置文件中不存在

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

我完全迷路了.

我尝试过:

  1. 仅在PCL上安装nuget-错误

  1. Installing nuget just on the PCL - error

在每个项目上安装-错误

Installing on every project - error

创建新的PCL,在其中实现该行,并将其添加为对主PCL的引用.从第二个PCL调用方法-错误.

Creating new PCL, implementing that line there, adding it as a reference to the main PCL. Calling a method from the second PCL - error.

推荐答案

我遇到了与您相同的错误,似乎在安装SignalRMicrosoft.AspNet.SignalR.Client程序包时,不能自动安装依赖程序包,因此引用被某种程度地破坏了.

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.

与Nuget分开安装以下三个软件包:

Install the following three Packages separately from Nuget:

SignalRMicrosoft.AspNet.SignalR.Client .

Newtonsoft.Json .

Microsoft.Net.Http .

这篇关于Xamarin.Forms中的SingalR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆