Xamarin: XLabs 2.0 iOS IGeolocator Woes

Having completed an Android app using Xamarin.Forms, I was tasked with making the iOS counterpart. Well it’s Xamarin so ‘write once, run everywhere’ right? Haha, ok sure.

This particular issue was pretty confusing but was related to changes in the XLabs breaking changes introduced in v2, in particular this inconspicuous line:

You will have to use DependencyService.Register<>() on your platforms packages to register XLabs Services.

Add this to your app delegate and you should be good to go:

DependencyService.Register<IGeolocator, Geolocator>();

There’s also this issue to watch out for too: https://github.com/XLabs/Xamarin-Forms-Labs/issues/657

Xamarin: aapt.exe exited with code 1

After adding the powered-by-google-on-white.png images to a project I’m working on, I’m suddenly hit with ‘aapt.exe exited with code 1’ whilst building. Did Google just give me some bad images? Nope!


It’s because of the use of the hyphens (-) in the filename. Remove them, rebuild and off you go!


After adding Google Maps support to your Xamarin.Forms solution, you try to build and receive this really helpful error. This seems to be triggered by the addition of the Google Play Services framework. It’s almost as helpful as ‘An Exception Occured’, another one of my favourites.

Luckily for this problem there’s a simple solution, increasing the Java heap size.

In Visual Studio open the project properties for your Android project and navigate to:

Android Options -> Advanced

Set the value of

Java Max Heap Size

to 1G.

P.S. Don’t forget to set this for each of your build configurations, otherwise come release time you’ll be scratching your head again. Or maybe that’s just me…In VS

Cocos2d-js v3.2 – Run on iPhone / Simulator

Just to be clear, this is for Cocos2d-js v3.2. Not Cocos2d-x.

Having built and tested your game locally, you want to run it on your iPhone or Android device, or maybe even in a simulator. How the hell do you do that? I have to say that the documentation is severely lacking here with lots of outdated advice.

Ignore anything that tells you to build for different targets from Bash. All of the code for each project type (iOS, Android, Mac, Win32) is sitting in your project folder already, albeit a little hidden.


You’ll see a few folders there, one for each platform. Inside the proj.ios_mac folder there’s an XCode project file which you can open up and build the app with.

The framework takes a few minutes to build, at least on my late 2010 MacBook Air so be patient.

Now I just need to solve the EXC_BAD_ACCESS when trying to run the damn thing…


My EXC_BAD_ACCESS is resolved and everything is running perfectly. I was being a bit naughty and taking advantage of Javascript’s lack of access modifiers.

I sub-class the PhysicsSprite object and during set up, I was setting the physics body of the sprite using the _body member. Of course when this is run in obj-C, the _body member isn’t accessible so boom! Instead I switched to using the PhysicsSprite.getBody() and setBody() methods, as I should’ve done in the first place…


this._body = new cp.Body(10, cp.momentForBox(Infinity, contentWidth, contentHeight));


this.setBody(new cp.Body(10, cp.momentForBox(Infinity, contentWidth, contentHeight)));

Revised: WPF Elliptical Layout Control – 3D!

The post WPF Elliptical Layout Control – 3D! was way more popular than I ever could have imagined with people still viewing and downloading the code daily. Not bad for a post that’s 6 years old! However, as you can imagine the code and solution are pretty outdated now with a few unresolved issues. Given the amount of views it still gets, I decided it was time to revisit it and see if I can bring it up to date.


Continue reading

Visual Studio Crashes and How to Recover a Corrupted .cs File

In spite of using source control, sometimes it’s still possible to lose work due to the quirks of computers. At least you can mitigate this and only suffer losing a few hours of work, but still, when those few hours were a stroke of genius, the likes of which cannot be reproduced, you can’t help but shed a tear when all is lost. But fear not, here are 4 techniques that you can try to recover your code with before crying.

Continue reading

ILoveToCode has a new Home (and name)

When I received an email from my hosting company that the domain samnoble.co.uk had expired, I realised I had completely forgotten I even owned this domain. I took it as an opportunity to finally put it to use, hosting my development blog.

I decided to go the self host route so that I’d have all the flexibility that comes with it, with no restrictions on plugins and themes etc. The free hosting on wordpress.com has been fantastic and served me well, but it’s time to move on!

After wondering if I should think up a new witty and creative name for the blog, I realised that there was no need. It’s my blog, on my domain so lets just leave it at that. Welcome to the old ILoveToCode and the new samnoble.co.uk.

Beware: WebUtility.UrlEncode vs HttpUtility.UrlEncode

Whilst experimenting with hash-based message authentication code (HMAC) request signing for a REST API I’m working on, I noticed that sometimes a signature would fail to validate server side, despite the hashing algorithm on both ends following the exact same algorithm. Upon closer inspection, it turned out that the client side URL encoding method was returning lowercase HEX values and the server side, when computing the string for hashing, was returning uppercase HEX values. Fair enough! The client was written in PHP and the server is .Net. There’s no standard requirement for the casing of url encoded values so some differences should be expected across platforms.

But would you expect that difference between two methods in the .Net framework? Experience tells you yes, but we can be hopeful all the same!

Continue reading

Debugger.Launch (.Net)

Now and then I come across a feature in .Net that I have managed to completely miss over the years. Whilst trying to figure out why a unit test was failing when running it, but passing whilst debugging, I came across this nifty feature.

Debugger.Launch will attempt to break the program execution and give you the chance to attach a debugger so you can examine what’s going on.

if (condition)

If the code is already running with a debugger attached, nothing will happen when the code is hit. If you want the code to break whether or not you have a debugger attached, you can use Debugger.Break instead.

Durable Task Framework – Testing a TaskActivity


You’ve created an orchestration using the Service Bus Durable Task Framework that makes use of several tasks, but you want to be able to test out each task in isolation.


The Durable Task Test Framework provides you with a utility class that makes creating and executing a new orchestration with a single task painless and easy. Whilst this isn’t a unit test by any stretch of the imagination, the MSTest framework is perfect for running your tasks one by one and making sure everything is as it should be.

How it Works

Creating and configuring an orchestration is relatively simple, but involves quite a few lines of code. If you’re just testing a single TaskActivity, there’s no point in doing that over and over again, so I created a simple helper class to take care of the grunt work!
Continue reading