Forum Cross Platform with Xamarin

Issue with Azure Mobile Services in iOS part of Cross Platform Project

LuisMarquesLuisMarques GBMember, University ✭✭
edited January 2015 in Cross Platform with Xamarin

Hello everyone. I have an issue with a cross platform app that I am building. Its a PCL project with android, iOS and Windows Phone sub-projects. I am using Visual Studio Professional 2013 update 4. I have installed Microsoft Azure Mobile Services 1.3.0 from Nuget. In the PCL common code part of the solution I have added all the code that initializes Azure in a static class called AzureHelper. This is a very simple test app which basically loads a bunch of notes from azure and lists them in the app's home page. This app works well when I set the project to run on Android and Windows Phone - it downloads the notes from azure and shows them on the app. The issue arises when I run the same code that runs on the other 2 on iOS. The iOS project Throws an exception:

**System.TypeInitializationException: An exception was thrown by the type initializer for PlatformHelpers.AzureHelper. **

I didn't change anything for the individual platform projects. All the code was added in the PCL common shared code. Given it works flawlessly for Android and Windows Phone, why doesn't the same code run on iOS? Any ideas on what might be wrong? I did some research online and found some posts of people saying you have to "hack" the platform specific projects to make Azure Mobile Services work, but I didn't have to do any platform specific coding for Android or Windows Phone - by platform specific i mean no line of code was added to those sub projects. Do I have to add some initialization code to the iOS project to make this work or is there an issue with the class definition below?

A portion of this class is listed below:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.MobileServices;
using NoteTakerPCL;
using Xamarin.Forms;

namespace PlatformHelpers
static class AzureHelper
static MobileServiceClient MobileService = new
MobileServiceClient("url", "key");
static IMobileServiceTable notetable = MobileService.GetTable();

    public static async Task LoadnotesAsync(long userid)
        IEnumerable<Note> extractednotes = await notetable.Where(note => note.userid == userid).ToEnumerableAsync();
        foreach (var note in extractednotes)

Best Answer


  • JeanFransJeanFrans FIMember
    edited December 2016

    Hi! I've issue with iOS project that I can't call method Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init() because assembly Microsoft.WindowsAzure.Mobile.Ext isn't referenced to the iOS project when updating MS Azure Mobile Services nuget package. At the moment iOS refrences Microsoft.WindowsAzure.Mobile assembly in ..\WindowsAzure.MobileServices.1.3.0\lib\portable-win+net45+wp8+wpa81+monotouch+monoandroid\Microsoft.WindowsAzure.Mobile.dll but there isn't extension assembly for that. After this I tried to reference directly to ..\WindowsAzure.MobileServices.1.3.0\lib\monotouch\Microsoft.WindowsAzure.Mobile.Ext.dll but after building iOS project comes an error:

    Error 2 Cannot include both 'monotouch.dll' and 'Xamarin.iOS.dll' in the same Xamarin.iOS project - 'Xamarin.iOS.dll' is referenced explicitly, while 'monotouch.dll' is referenced by 'Microsoft.WindowsAzure.Mobile.Ext, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. XamarinTodo.iOS

    Code in iOS AppDelegate looks like this:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
                LoadApplication(new App());
                return base.FinishedLaunching(app, options);

    WP and Android works correctly but iOS doesn't. Any suggestions how to fix this, thanks!

  • NicholasRogoffNicholasRogoff GBUniversity ✭✭

    I am also getting the issue

    Cannot include both 'monotouch.dll' and 'Xamarin.iOS.dll' in the same Xamarin.iOS project - 
    'Xamarin.iOS.dll' is referenced explicitly, while 'monotouch.dll' is referenced by 
    'Microsoft.WindowsAzure.Mobile.Ext, Version=

    when I include the following in AppDelegate.FinishedLaunching


    Without it, the IOC complains with error:

    System.InvalidOperationException: A Microsoft Azure Mobile Services assembly for the current platform was not found.
    Ensure that the current project references both Microsoft.WindowsAzure.Mobile and 
    the following platform-specific assembly: Microsoft.WindowsAzure.Mobile.Ext


    Anyone have an answer for this!. My Winphone and Android projects are OK. Just iOS!!

  • KingWilderKingWilder USMember

    I've gone through this many times, and I got something to work. The problem is that "monotouch" needs to be removed for the new upgrade.

    In your iOS project, do the following:

    1) Download the components -
    2) Remove monotouch - in your iOS References, remove the monotouch assembly
    3) Add reference - now add a reference to the new Azure Mobile Services from the component store that you downloaded. From the extracted zip file, in folder azure-mobile-services-1.3.1/lib/ios-unified, select Microsoft.WindowsAzure.Mobile.dll (and .xml), and Microsoft.WindowsAzure.Mobile.Ext.dll (and .xml), in your Visual Studio iOS project references, and add them. Also add the Newtonsoft.Json assembly if it's not there, and you may need to upgrade the System.Net.Http assemblies that are in this folder.

    Evidently iOS needs different Azure Mobile Services than the one from NuGet. I hope this helps.

  • tmontez36tmontez36 USMember ✭✭

    I have tried all the suggestions here and Im still running into the same error:

    "System.TypeInitializationException: An exception was thrown by the type initializer for..."

    I followed the pattern of the quick start code that I downloaded from azure exactly and I still havent been able to get this to work.

    Any other suggestions?

  • tjr77tjr77 FRMember ✭✭

    From my side the easy way was to downgrade the _"Microsoft.Azure.Mobile.Client" _to a previous version and it solved it

Sign In or Register to comment.