2
votes

I currently have a Xamarin.Android project that references a .NET Standard 1.1 library that references AutoMapper 5.0.2.

When I try to build this through VSTS I get this error

C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1316,2): Error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Collections.Specialized, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?

This solution builds perfectly fine on my local machine and runs in the Android Emulator.

Things I have tried (and none have worked)

  1. Installing the AutoMapper Nuget package directly against the Android Project.
  2. Installing System.Collections.Specialized in the Android project.
  3. Doing <CopyNuGetImplementations>true</CopyNuGetImplementations> in the Android Project.

Also just as a side note, I have .NET Standard 1.1 Libraries all the way through my project, yet I can see from the build log that its using .NET Standard 1.3. Not sure if this will make a difference as I am not sure how the build process manages these standards.

Copying file from "C:\Users\buildguest.nuget\packages\AutoMapper\5.0.2\lib\netstandard1.3\AutoMapper.dll" to "C:\a\1\b/Release\AutoMapper.dll".

Update 1

Just to add that I have tried using Nuget 3.4.4 and Nuget 3.5.0-beta2 in the build agent and while this solved other issues I was having, it didn't resolve the current one I am experiencing.

Update 2

Here is my Android project.json

{
  "dependencies": {
    "Newtonsoft.Json": "9.0.1"
  },
  "frameworks": {
    "MonoAndroid,Version=v6.0": {}
  },
  "runtimes": {
    "win": {}
  }
}

Here is my Portable project.json

{
  "supports": {},
  "dependencies": {
    "AutoMapper": "5.0.2",
    "NETStandard.Library": "1.6.0",
    "Xamarin.Forms": "2.3.0.107"
  },
  "frameworks": {
    "netstandard1.1": {
      "imports": "portable-win+net45+wp8+win81+wpa8"
    }
  }
}

Update 3: 18th July Just adding more test cases

  1. Did a brand new Xamarin Android project, with packages.config, existing nuget.exe. All works.
  2. Add AutoMapper reference, builds and runs locally. Fails in VSTS Build Agent
  3. Updated Nuget.exe - still fails on build
  4. Update to project.json - still fails on build.

I can not get even a blank project with an AutoMapper 5.0.2 reference working in the Visual Studio Build step of VSTS. Always the same error as above.

2
Are you using "Xamarin.Android" build definition template? Can you try with "Visual Studio" build definition template to see if the build can be completed successfully?Eddie Chen - MSFT
@Eddie-MSFT - I just tried with a Visual Studio Build step and received the exact same error as above.Adam
I get the same error with "Xamarin.Android" build definition template but the build works with "Visual Studio" template.Eddie Chen - MSFT
@Eddie-MSFT - I continue to get the error on either Xamarin.Android or Visual Studio. I have edit the question above to show my project.json files for the droid and portable project to see if there is something I am missing or different.Adam
Also just noting that I also just tried referencing AutoMapper directly on the droid proj with a Visual Studio build step and still the same error.Adam

2 Answers

1
votes

I believe you'll need to add a build step to download the latest NuGet.exe on build and then either call nuget restore via a build script or configure the alternate path of the VSTS NuGet Restore task to use the one you downloaded.

The issue is that the NuGet.exe bundled with VSTS is too old.

You can find the direct download paths here: https://dist.nuget.org/index.html

1
votes

This is caused by the old Xamarin version installed on Hosted Build Agent. The version installed on hosted build agent is "Xamarin for Visual Studio 4.0.3.214". I deployed an on-premise build agent and installed this version, and then queue a build with this build agent, the build will fail with the same error message. After I upgrade the version to the latest 4.1.1.3 version, the build is completed successfully.

So the work around for this issue is deploy your own build agent and install the latest Xamarin on it. And then run your build with this on-premise build agent.