Will #script run on an IOS device?

In the past, Apple has blocked IOS developers from running scripts on the device.

Has anyone attempted to pass #script code from a server to a mobile running IOS?

System.Reflection.Emit

The lack of System.Reflection. Emit means that no code that depends on runtime code generation will work. This includes things like:

  • The Dynamic Language Runtime.
  • Any languages built on top of the Dynamic Language Runtime.
  • Remoting’s TransparentProxy or anything else that would cause the runtime to generate code dynamically.

Important

Do not confuse Reflection.Emit with Reflection . Reflection.Emit is about generating code dynamically and have that code JITed and compiled to native code. Due to the limitations on iOS (no JIT compilation) this is not supported.

But the entire Reflection API, including Type.GetType (“someClass”), listing methods, listing properties, fetching attributes and values works just fine.

Never tested, it can work in theory since ServiceStack.Text Reflection Utils utilizes cascading reflection implementations available in different platforms.

An issue with scripting languages in iOS is in mono’s AOT tree-shaking where it’s not going to know which symbols scripts uses & so strips them away if not used by the compiled App. This was also an issue with Scripting Unity3D where it needed to create Script Method Wrappers around a lot of Unity’s APIs to prevent them from being stripped out of the AOT build.

I think you passed the first hurdle considering you fall back from Reflection Emit to Compiled Expression Trees.

The rest of it can be worked around, as you say with static references to symbols.

Thanks

Potentially, there are also other ways to prevent tree-shaking in Xamarin, though I’ve not had a great dev experience with libs that use a lot of Reflection in Xamarin/IOS, maybe it’s improved since.

1 Like

We link with Link SDK assemblies only because the full linker is way to aggressive.

The DEV experience is better using Rider on Mac or Windows. I’m on Linux and Rider just broke for Xamarin development and im not sure if their going to fix it.