IOC, Generics and Reflection with regard to mobile platforms?

Basically, can Unity handle Inversion of Control, Dependency Injection and Reflection when working with mobile platforms? Particularly iOS? What limits are imposed when using things like Interfaces and Generics?

I haven’t encounter any issue so far on iOS, or limits when it comes to interfaces or generics. You just have to make sure that class that are only referenced by reflection are not stripped from the final bytecodes.

The only limits I know of with generic is, Unity is unable to properly serialized a generic, even if it derived from ScriptableObject/MonoBehaviour. You need to make a non-generic class to derive from your generic one for serialization to work properly.

I have encountered issues on iOS when using some of the cryptography classes and bytecode stripping/micro mscorlib. Some vital classes, accessed only via reflection, were removed from the assembly and I was getting runtime exceptions. The solution was to add the System.Security.Cryptography namespace to the link.xml file in our assets folder.

Unity docs cover this sort of thing here:

iOS doesn’t allow to generate code in runtime, so many JIT features is not supported, for example LINQ or even so simple example:

public static string ArrayToString<T>(T[] array)
{
    string result = "";
    foreach(T t in array)  
        result += t.ToString();
    return result;
}

In addition, unity contains only tiny part of .net (try to find Complex class:p)

Frankly, I don’t see why your example wouldn’t work on iOS.

It’s weird. It is simplistic code from my project (debugging arrays). When unity tries to invoke this code, simply throws exception (i don’t remember what exception exactly, something like JIT cannot compile this code).
I had many problems similiar to this (min. 30-40 times) and all those problems occur only on iOS

The error message should get you pointed the right way in regards to solving that weirdness. :wink:

iOS doesn’t use a JIT, it uses AOT instead, and the AOT pass at build time can miss generics sometimes in seemingly random cases. I’m pretty sure the problem Gibbonator’s post mentions is also somehow related to this, and I think the solution is the same.