How should i use Azure Mobile Services with PCL or without it now?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 12:02:00

First, make sure you are using version 1.1.5 or above of either the NuGet or the Xamarin Component as previous versions had some issues with PCL support.

For a step by step guide on using Mobile Services in a PCL, see this tutorial.

If you install the Xamarin Component or the NuGet package for Azure Mobile Services into your Android application, you will find it adds these references (among others):

  • Microsoft.WindowsAzure.Mobile.dll
  • Microsoft.WindowsAzure.Mobile.Ext.dll

The first assembly is a PCL, the second assembly has platform specific implementation (and that is what you are missing with the error message above).

The NuGet package for Mobile Services has specific platform targets defined for Xamarin.iOS and Xamarin.Android so if you are using Visual Studio, you have the option to use just the NuGet and skip the Xamarin component completely.

Due to some bugs in how the BCL NuGet packages (HttpClient, Bcl.Build, etc) interact with Xamarin, there are a few workarounds you'll need to be aware of. See the tutorial above for the necessary steps.

Make sure you have called

CurrentPlatform.Init(); 

before instantiating the mobile service client

Here's how I got Mobile Services v1.3.2 working in new Xamarin.Forms PCL project:

  1. Install 'Mobile Services’ into shared project ‘Packages’ folder as well as .iOS & .Droid ‘Packages' folders.
  2. Delete duplicate references in .iOS / .Droid folders: “System.Runtime”, “System.IO”, “System.Threading.Tasks"
  3. Remember to add CurrentPlatform.Init(); to ‘AppDelegate.cs' in .iOS project and to ‘MainActivity.cs' in .Droid project.

Paul Batum has done a good sample Xamarin PCL app showing syncing between iOS and Android app: https://github.com/paulbatum/fieldengineerlite

Make sure you've installed the latest version of NuGet. That should fix the issue where Newtonsoft.Json won't install in the PCL.

For Azure Mobile Services, if you still have trouble I'd recommend following the steps in the getting started guide to download a preconfigured sample project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!