Tuesday, December 23, 2014

Mailing using Device.OpenUri on iOS in Xamarin Forms

Short version

Device.OpenUri will not work if passing it a mailto-uri on iOS that contains spaces or escaped spaces. Check out work around at the bottom.

Long version

The "issues" are iOS specific since Android seems to swallow all that comes its way.

The starting point is these two lines of code placed somewhere in the shared code (PCL or shared) in a Xamarin Forms solution.

    var uri = "mailto:info@johankarlsson.net?subject=subject&body=body";
    Device.OpenUri(new Uri(uri));

This works fine!

Adding spaces, not working

    var uri = "mailto:info@johankarlsson.net?subject=more in subject&body=body";
    Device.OpenUri(new Uri(uri));

This gives you an "System.Exception: Could not initialize an instance of the type 'MonoTouch.Foundation.NSUrl': the native 'initWithString:' method returned nil."

Alright, so we URI encode it to

    var uri = "mailto:info@johankarlsson.net?subject=more%20in%20subject&body=body";
    Device.OpenUri(new Uri(uri));

Same issue... And that's a bit weird since Apples own documentation states that this is the way to do it. (https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MailLinks/MailLinks.html#//apple_ref/doc/uid/TP40007899-CH4-SW1)

Trying Apples own example Uri

With a copy of the example Uri from Apples documentation it should work.

    var uri = "mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20";
    Device.OpenUri(new Uri(uri));

It does not.


This seems to be a bug for Bugzilla to handle... (https://bugzilla.xamarin.com/show_bug.cgi?id=25584)


Friday, December 19, 2014


Another short tip

When cloning a project for use on Mac and Xamarin Studio that was originally created in Visual Studio on PC, you might encounter a "Could not find part of the path" build error.

It's simply just some missing folders.

For example, if the error looks something like this:

Error: Could not find a part of the path "/Users/johankarlsson/Projects/TheProject/TheProject.Core/obj/Debug/TheProject.Core.csproj.FilesWrittenAbsolute.txt".

Simply create the obj/Debug folder missing and the build will succeed.

Thursday, December 18, 2014

"The memory needed by this VM exceeds the driver limit"

Short tip!

If you run into the error message "The memory needed by this VM exceeds the driver limit." when running a x86 emulator from intel and Android 5 (API level 21), just reinstall HAXM and assign more memory. About 3GB should do it.

Download Intels HAXM from


For more info on setting up HAXM in Parallells, check out Daniels blogpost.