Having trouble installing some NuGet packages on Xamarin projects in Visual Studio 2015?

In software development there is always, and I mean always, something that will turn that sincere joy of coding into a living nightmare and when you’re starting a new project you can be sure that it has something to do with package management, dependencies and versioning of those dependencies. It might be those Cocoapods, those Maven artifacts or in this case: NuGet packages.

This weekend I was coding on a project using the real-time framework SignalR and so I wanted to use the client libraries that existed for .NET. The SignalR Client package works on most if not all the platforms, but it has a couple of dependencies that might fail to install.

It seems that if you try to install the package Microsoft.Net.Http on a Xamarin iOS or Android project you can get these kinds of messages popping up:

Could not install package ‘Microsoft.Bcl.Build 1.0.14’. You are trying to install this package into a project that targets ‘Xamarin.iOS,Version=v1.0’, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Could not find System.Net.Http.Extensions referenced by assembly Microsoft.AspNet.SignalR.Client, Version=2.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

 

The Microsoft.Net.Http package has dependencies on the Microsoft.Bcl and Microsoft.Bcl.Build packages, and the culprit will be the Microsoft.Bcl.Build package.

After a while of swearing at the NuGet package manager and wishing I’d take other choices in my life I tried installing the dependencies manually.

It worked.

Turns out Microsoft.Bcl.Build has a newer package than 1.0.14 that supports the latest and greatest bits from Xamarin, and for some reason the Microsoft.Net.Http package does not know about it or hasn’t been updated to reference the newest one.

If you’re having similar problems then try to install the dependencies manually because you never know, it might just work..

Xamarin Android: You are trying to install this package into a project that targets ‘MonoAndroid,Version=v2.2’

Today I created a new Xamarin Android project, and I wanted to test out Material Design on my phone (still runs 4.4.2) using the revamped AppCompat v4 library. To my disappointment I was unable to install the AppCompat NuGet package:

Turns out this can be a common problem when using Visual Studio and the “Compile using Android version” is not explicitly set. The default in my case is “Use Latest Platform”. What this does is making VS to add the proper TargetFrameworkVersion property in the .csproj file. It seems that sometimes this does not get set at all when creating a project and “Use Latest Platform” is set. Weird. In any case, setting this explicitly fixes things and NuGet understands which version of MonoAndroid to use. The default is 2.2, but we want something newer, preferably Android Version 5.

So change this:

01-compile-using-latest

To this:

02-compile-with-21

Reload the project when asked by Visual Studio and install the package again!

Thanks to the awesome community over at the Xamarin Forums for being on top of this already — check out the post here.

UPDATE: Haha, never mind the blurred out assembly name in the first image. Don’t know why I did that 😉

Xamarin iOS: Build host too old?

Hey guys,

I just wanted to post a quick tip a way to resolve the error “The build host is too old for this version of Xamarin.iOS extension” in Visual Studio. This seems to occur if you recently set up a proxy of some sorts or have installed a tool like Fiddler.

I had just installed Fiddler to capture HTTP packets for monitoring my requests and responses when communicating with a back-end. Turns out Fiddler had enabled a proxy of a sort that disrupts the Xamarin Build host connection into thinking that the build host is too old.

Opening up Fiddler and turning off all the Proxy-settings I could find, the connection was fixed and I could build again. Happy days.

 

Xamarin iOS: Could not instantiate class named MKMapView

This might not occur that often in your projects but if you find yourself dropping a MapView on your storyboard and then just running the app you will most certainly will experience a crash. Why?

  1. Make sure you have enabled Map services in your Info.plist file
  2. Make sure you give your MapView a name (that automagically creates an outlet)

If you don’t give your MapView a name then the Xamarin/Mono linker will not link in the MapKit framework due to it not being used in code.

Xamarin: Using the ABPeoplePickerNavigationController in iOS 8

Hi guys, I thought I would post a quick snippet demonstrating one way of dealing with the ABPeoplePickerNavigationController in iOS 8. If you have noticed that the SelectPerson event is not firing anymore then you are not alone.

The new way of dealing with the controller is using a seperate delegate class and assigning it to the ABPeoplePickerNavigationController using the Delegate property. This can give a nice seperation of concerns but can quickly get messy, so I created a new basic class that creates a layer of abstraction and implements the async/await pattern in doing so as well.

Please feel free to comment, edit, improve and use it as you please.

AsyncPeoplePicker

As JoeAshbrook pointed out, this code won’t run well when doing so in another thread. He posted the following adjustment:

 

Usage

Hopefully this can help you in your ways of dealing with the ABPeoplePickerNavigationController.