Introducing the Xamarin.iOS Interpreter

Chris Hamons

Historically iOS applications have had a number of limitations when running on a device, as Apple disallows the execution of dynamically generated code. Applications are compiled “Ahead of Time” (AOT) before deployment because of this. You can read more about this architecture here.

“Ahead of Time” AOT

In most cases, AOT can provide performance benefits. It can also restrict a number of C# features from being used:

  • Assembly.Load and System.Reflection.Emit
  • Some uses of the C# dynamic feature

The team has been hard at work at overcoming these limitations while abiding by platform restrictions. The result is a new interpreter for Xamarin.iOS.

The Interpreter

Today we are promoting this experimental work into a preview ready for general testing.

The Interpreter, as the name implies, allows you to interpret at run time some C# parts of your application while compiling the rest ahead of time as usual.  Get started previewing by installing the packages below:

Visual Studio 2019: Xamarin.iOS Installer Visual Studio for Mac 8.0: Xamarin.iOS Installer

Once you have the preview installed (don’t forget your Mac build host), you can enable the interpreter by:

  • Opening the project’s options
  • Switch to iOS Build
  • Adding --interpreter to the Additional mtouch arguments.

We have some small samples available which show off some of the new functionality.

Known Issues

Try It Out!

Please take the new interpreter for a spin and provide feedback here: https://github.com/xamarin/xamarin-macios/issues/new

5 comments

Discussion is closed. Login to edit/delete existing comments.

  • Mike Simon 0

    Does this mean we’ll be able to use generics with functions like this:
    public async Task<T> Post(string url, object byteContent) {
        …
       return JsonConvert.DeserializeObject<T>(result); 
    }

    Going back to deserializing inside the calling function was painful 🙂

  • Homero Lara 0

    Wow, I didn’t realize MS was working on something like this. Looks extremely promising. 

  • Chris Timberlake 0

    For people wondering, This solves the MongoDB.BSON issue with AOT Compilation on iOS. It fixes the BSON Serialization, System.Reflection.Emit failures as well.

  • Alvaro Rivoir 0

    Is this already in the stable channel?

  • Jason Willett 0

    This extension can’t be installed as of VS 16.4.5: “Install Error : System.InvalidOperationException: Installation of Microsoft.VisualStudio.Android.DeviceManager failed. The extension has a lower version than required by Visual Studio. Please install the extension from Visual Studio Installer instead.”

Feedback usabilla icon