문제

C#과 Mono의 전체 AOT 기술을 사용하여 iPhone을 위해 개발 중입니다. 그들의 제한 페이지 (링크 텍스트), 기존의 모노/.NET과 달리 iPhone의 코드는 JIT 컴파일러에 의해 요구되는 대신 정적으로 컴파일됩니다.

하드웨어에서 실행될 때 다음과 같은 예외가 발생합니다.

ExecutionEngineException: Attempting to JIT compile method 'System.Reflection.MonoProperty:GetterAdapterFrame<Image, UnityEngine.Color> (System.Reflection.MonoProperty/Getter`2<Image, UnityEngine.Color>,object)' while running with --aot-only. 

System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) [0x00000] 
Ani+AniValue.Get () 
Ani.CreateAnimations (System.Object obj, System.Collections.Hashtable properties, Single duration, System.Collections.Hashtable options, AniType type) 
Ani.Method (AniType type, System.Object obj, Single duration, System.Collections.Hashtable _properties, System.Collections.Hashtable _options) 
Ani.From (System.Object obj, Single duration, System.Collections.Hashtable _properties) 
xObject+<>c__CompilerGenerated5.MoveNext () 
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) 
xObject:StartAnimation(Animate, GameObject, Object, Object) 
SceneSplash:CreateBackground() 
SceneSplash:OnSetup() 
SceneSplash:OnSceneActivate(Callback) 
GameController:ActivateScene() 
GameController:DeactivateScene() 
GameController:SceneLoaded(Scene, GameObject, SceneBase) 
SceneBase:Start()

제한 문서에 따르면 System.Reflection.emit은 지원되지 않지만, 반사의 측면으로, "type.getType ("someclass "), 나열 메소드, 목록 속성, 속성 가져 오기를 포함한 전체 반사 API. 그리고 가치는 잘 작동합니다. "

예외를 일으키는 코드를 포함 시켰습니다 ...

void CreateAnimations(System.Object obj, Hashtable properties, float duration,
                      Hashtable options, AniType type)
{
    foreach (DictionaryEntry item in properties)
    {
        name = (string)item.Key;                  // Extract name and value
        System.Object value = item.Value;

        AniValue foo = new AniValue(obj, name);   // Create value object

        /* To exception occurs inside Get() */
        System.Object current = foo.Get();        // Get current value

        ...

위의 메소드는 해시 테이블에서 속성 이름을 가져 와서 OBJ와 함께 사용하여 Anivalue 인스턴스를 만듭니다. 그 후에, foo.get ()는 부동산의 가치를 검색하기 위해 호출됩니다. 예외는 PropertyInfo.getValue (obj, null)에서 발생합니다.

using System.Reflection

public class AniValue
{
    static BindingFlags bFlags = BindingFlags.Public | BindingFlags.NonPublic
                                 | BindingFlags.Instance | BindingFlags.Static;

    System.Object obj;  // Object a field or property is animated on
    string name;        // Name of the field or property

    System.Type objType;          // Type object
    FieldInfo fieldInfo;          // FieldInfo object
    PropertyInfo propertyInfo;    // PropertyInfo object

    public AniValue(System.Object o, string n)
    {
        obj = o;
        name = n;
        objType = obj.GetType();
        fieldInfo = objType.GetField(n, AniValue.bFlags);
        propertyInfo = objType.GetProperty(n, AniValue.bFlags);
        if (fieldInfo == null && propertyInfo == null)
        {
            throw new System.MissingMethodException("Property or field '" + n
                                                    + "' not found on " + obj);
        }
    }

    // Get field or property
    public System.Object Get()
    {
        if (propertyInfo != null)
        {
            /* The next line causes the Exception */
            return propertyInfo.GetValue(obj, null);
        }
        else
        {
            return fieldInfo.GetValue(obj);
        }
    }
    ...

C#, JIT, AOT 및 Reflection에 대한 경험이 제한되어 있지만 GetValue () Trigger JIT가 필요합니까? UnityEngine.color는 구조물이며 이미지 클래스는 Xobject의 서브 클래스이며 UnityEngine.monobehaviour의 서브 클래스입니다. 색상은 이미지의 속성이며 코드가 예외가 발생할 때의 값을 얻을 수있는 것입니다.

흥미롭게도 .NET 1.1을 사용하여 코드를 컴파일 할 수 있으며 모든 것이 정상적으로 실행됩니다. .NET 2.1을 사용하여 컴파일 할 때만 예외가 발생합니다.

나는 해결책이 있는지 여부를 모르겠지만, 원인에 대한 통찰력에 관심이있을 것입니다.

도움이 되었습니까?

해결책

IIRC, 반사를 통한 제네릭에 대한 경고도 있습니다. 나 믿다 콘크리트 유형이 아닌 인터페이스를 호출하지만 동일하게 적용 할 수 있습니다. 특정한 반사를 사용할 때.

개인적으로, 나는 iPhone을 다룰 때 반성을 떨어 뜨립니다. 더 쉽습니다. 나는 여전히 메타 프로그래밍을하고 있지만, 정기적 인 코드 (전체 프레임 워크)를 사전 생성하고있는 다음 Monotouch로 가져갑니다. 그것은 매우 견고하게 작동하는 것 같습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top