System.Type.GetType returns null on 32bit devices using 4.6.6p2 and p3 on Universal il2cpp builds

Hi,

We were testing our game in iOS devices using lastest unity patches and we discovered an strange behaviour using latest p2 and p3 patches of 4.6.6 in 32bit devices only (p1 patch appears to work properly).

The error comes when using in an script:

System.Type t = System.Type.GetType(typeName);

In generated cpp code and only in 32 bit devices the returned type is null while in 64bit devices is returned correctly. Also we tested this error in 4.6.6p1 and 4.6.6f1 and appears to work properly.

We deep down in generated code and all appears to be happening inside the call:

extern "C" Type_t * Type_GetType_m15709 (Object_t * __this /* static, unused */, String_t* ___typeName, const MethodInfo* method)

And going deeper:

extern "C" Type_t * Type_internal_from_name_m31329 (Object_t * __this /* static, unused */, String_t* ___name, bool ___throwOnError, bool ___ignoreCase, const MethodInfo* method)
{
    typedef Type_t * (*Type_internal_from_name_m31329_ftn) (String_t*, bool, bool);
    static Type_internal_from_name_m31329_ftn _il2cpp_icall_func;
    if (!_il2cpp_icall_func)
    _il2cpp_icall_func = (Type_internal_from_name_m31329_ftn)il2cpp_codegen_resolve_icall ("System.Type::internal_from_name(System.String,System.Boolean,System.Boolean)");
    return _il2cpp_icall_func(___name, ___throwOnError, ___ignoreCase);
}

Our gessings are the code behind _il2cpp_icall_func is working different when you’re in 32bit or 64bit and the result of this function is null or the expected class in each case.

Any ideas? This doesn’t happen in 4.6.6p1 version.

1 Like

Issue confirmed in an empty project.

I’ve created a new project with a single scene and a GameObject with the following Monobehaviour added:

using UnityEngine;
using System;
using System.Collections;

class TestClass {}

public class TestFail : MonoBehaviour {

    void OnGUI () {
        System.Type testClassType = System.Type.GetType("TestClass");
        if (testClassType != null) {
            GUI.Label(new Rect(0, 0, Screen.width, 100), "<color=green><size=40>Class loaded: " + testClassType.Name + "</size></color>");
        } else {
            GUI.Label(new Rect(0, 0, Screen.width, 100), "<color=red><size=40>ERROR LOADING CLASS</size></color>");
        }
    }
}

And in a 32bit device the error is still there showing the text “ERROR LOADING CLASS” instead of the “Class loaded” message as in 64bit devices.

Same example tested on 4.6.6p1 and works without problem not showing the red message

@brovadorion

Thanks for reporting this. I’m a bit surprised by the difference in behavior between the 32-bit and 64-bit builds. We will investigate this though, as it looks like a regression from 4.6.6p1 behavior.

Thanks for the quick answer!

We actually have a fix now for this bug, it should be available in the 4.6.7p1 and 5.1.1p3 patch releases.