3
votes

Good day.

I want to create NUnit tests for my PCL xamarin library. There are 1.1.0 Azure Mobile Service in xamarin components right now and 1.1.1 in NuGet

As i understand i need MobileServices.Ext for each platform, so i need 1.1.0 version for windows. Am i right? Is so, where can i find it?

I tried to add Microsoft.WindowsAzure.Mobile from xamarin Component store (version 1.1.0 in store, file version 1.0.0) and Microsoft.WindowsAzure.Mobile.Ext from Nuget (version 1.1.0)

here is exception

System.TypeInitializationException : Инициализатор типа "RateIt.Backend.SAL.AzureWorker" выдал исключение. ----> System.IO.FileLoadException : Не удалось загрузить файл или сборку "Microsoft.WindowsAzure.Mobile.Ext, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" либо одну из их зависимостей. Найденное определение манифеста сборки не соответствует ссылке на сборку. (Исключение из HRESULT: 0x80131040)

unit tests project needs this: Microsoft.WindowsAzure.Mobile.Ext, Version=1.0.0.0

as @TheESJ adviced it tried to add bindings

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.Mobile.Ext" publicKeyToken="null" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

That doesn't help. Right now i found workaround: "linked project extension" with all files from PCL linked to project with tests, so i can use azure from NuGet and don't bother about PCL

2
You need to redirect to the version that you deploy with your unit test. This would be 0.0.0.0-1.1.0.0 > 1.1.0.0. - TheESJ

2 Answers

0
votes

Version 1.1.0 of the NuGet package and Xamarin component had some issues when used together. As of Version 1.1.5 this is no longer the case, you should find they work together seamlessly.

Also, version 1.1.5 of the NuGet package supports Xamarin.iOS and Xamarin.Android targets, so if you are using Visual Studio only you can skip the component completely.

For more information see this tutorial.

2
votes

You can provide a bindingRedirect in the app.config for the unit test and the unit test runner should honor this when loading the unit test assembly. Nuget does this automatically for applications, but not class libraries. If you have an application you can copy the binding redirects from there.