Yanayaya
Yanayaya

Reputation: 2184

Why is my Xamarin Forms iOS app crashing when using Microsoft Azure Mobile Services

I am having a strange problem with my Xamarin Forms app that I can't seem to solve, I seem to be going around in circles with it instead. It seems to be tied to my iOS project specifically and it surrounds the assembly reference Microsoft.WindowsAzure.Mobile. When I run my app on my iPhone simulator and then try to view any part of it that gets data from Azure the following message is triggered.

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.

I find this strange because I have installed what I believe to be all the correct references which are:

Entire solution used Xamarin.Forms v2.3.4.247

MyApp(Portable)

MyApp.iOS

I thought perhaps the app.config of the iOS project was corrupt or perhaps missing some information when I'd installed these nuget packages so I have a quick look and it all looked like it should.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.0.0" newVersion="1.5.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="PInvoke.BCrypt" publicKeyToken="9e300f9f87f04a7a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-0.5.0.0" newVersion="0.5.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Validation" publicKeyToken="2fc06f0d701809a7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.4.0.0" newVersion="2.4.0.0" />
      </dependentAssembly>
     <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.Mobile" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

I can provide more code if needed but I wanted to keep the problem localised to what I have seen and where it reports the problem to be. Does anyone know what could be causing this or what I need to do to resolve it? Could it perhaps be versions that are causing the problem and should I consider rolling back?

Upvotes: 0

Views: 195

Answers (1)

Bruce Chen
Bruce Chen

Reputation: 18435

AFAIK, WindowsAzure.MobileServices is now deprecated and it used to work with Mobile Services (domain like {your-app-name}.azure-mobile.net). While Microsoft.Azure.Mobile.Client is used to work with Mobile Apps (App Service, domain like {your-app-name}.azurewebsites.net).

Does anyone know what could be causing this or what I need to do to resolve it? Could it perhaps be versions that are causing the problem and should I consider rolling back?

I noticed that the app.config of your iOS project has the dependentAssembly about Microsoft.WindowsAzure.Mobile with the newVersion 1.3.0.0.

Per my understanding, you have installed both WindowsAzure.MobileServices and Microsoft.Azure.Mobile.Client packages, I would recommend you using the same package to narrow this issue. Also, you need to initialize azure mobile by the following code before you using MobileServiceClient:

Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();

Moreover, I checked my xamarin.forms application which has installed Microsoft.Azure.Mobile.Client 3.1.0, it could work as expected. Here is the git sample about azure-mobile-apps-quickstarts, you could refer to it. Additionally, here is a similar git issue, you could refer to it here.

Upvotes: 0

Related Questions