Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

IL2CPP Type.MakeGenericType work around

Discussion in 'iOS and tvOS' started by JoshPeterson, Mar 18, 2015.

  1. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    IL2CPP is limited in how many nested levels of generic types it can handle. The type of responseList is List<KeyValuePair<string, List<KeyValuePair<string, List<KeyValuePair<string, List<KeyValuePair<string, string>>>>>>>> pushes past that limit, since it has seven nested generic type levels.

    Can you simplify this type a bit? That should work around this this error.
     
  2. zero27x

    zero27x

    Joined:
    Mar 22, 2018
    Posts:
    4


    Thanks for the answer, but how approximately do I need to change the type so that it has similar properties? I would be grateful if you give me an answer
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    I don't know the specifics of your use case, so I can't say for sure. Can you flatten it out? It looks like you have many nested pairs, with a pair of strings at the bottom of the hierarchy. Rather than expressing this type as a bunch of nested generics, can you make non-generic types instead?
     
  4. zero27x

    zero27x

    Joined:
    Mar 22, 2018
    Posts:
    4
    if it helps someone, this is what I ended up with
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using UnityEngine;
    5.  
    6. public class OutParser : MonoBehaviour
    7. {
    8.     List<OutParserStruct> responseList = new List<OutParserStruct>();
    9.  
    10.     public OutParser(string strOut = "")
    11.     {
    12.         if (strOut.Trim().Length != 0)
    13.         {
    14.             getParsedList(strOut);
    15.         }
    16.     }
    17.  
    18.     private void getParsedList(string str)
    19.     {
    20.          str = str.Trim();
    21.         string[] splitted = str.Split(';');
    22.         List<string> _splitedList = splitted.ToList();
    23.         _splitedList.RemoveAll(item => item == "");
    24.  
    25.         splitted = _splitedList.ToArray();
    26.  
    27.         for (int i = 0; i < splitted.Length; i++)
    28.         {
    29.             OutParserStruct resp = new OutParserStruct();
    30.             string var_change = splitted[i];
    31.             if (var_change.Length > 0)
    32.             {
    33.                 string[] splitted_var = var_change.Split('.');
    34.                 string varClass = splitted_var[0];
    35.                 resp.ClassKey = varClass;
    36.                 string action = "equal";
    37.                 string[] subVarSplitted = splitted_var[1].Split('=');
    38.                 string varName = subVarSplitted[0];
    39.                 string value = subVarSplitted[1];
    40.                 switch (subVarSplitted[1][0].ToString())
    41.                 {
    42.                     case "/":
    43.                         action = "divide";
    44.                         value = value.Substring(1);
    45.                         break;
    46.  
    47.                     case "*":
    48.                         action = "multiply";
    49.                         value = value.Substring(1);
    50.                         break;
    51.  
    52.                     case "+":
    53.                         action = "plus";
    54.                         value = value.Substring(1);
    55.                         break;
    56.  
    57.                     case "-":
    58.                         action = "minus";
    59.                         value = value.Substring(1);
    60.                         break;
    61.  
    62.                 }
    63.                 resp.Action = action;
    64.                 resp.Value = value;
    65.                 resp.VarKey = varName;
    66.             }
    67.             responseList.Add(resp);
    68.         }
    69.     }
    70.  
    71.     public List<OutParserStruct> getOutChanges()
    72.     {
    73.         return responseList;
    74.     }
    75. }
    76.  
    77. [Serializable]
    78. public class OutParserStruct
    79. {
    80.     public string ClassKey;
    81.     public string VarKey;
    82.     public string Action;
    83.     public string Value;
    84. }
    85.  
     
  5. dthurn

    dthurn

    Joined:
    Feb 17, 2015
    Posts:
    77
    Is the limit of 7 configurable at all? I am interested in the standard .NET System.Collections.Immutable library, but it uses more than 7 layers of nesting...

    Edit: Ah, you can just run something like PlayerSettings.SetAdditionalIl2CppArgs("--maximum-recursive-generic-depth 30"); before you build.
     
    Last edited: Jan 15, 2021
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    I think you want --maximum-recursive-generic-depth=30. However. I would not put it that high! Doing so will make the build take a long time and will make the code size huge, likely. I'd recommend you try something closer to the default value first.
     
  7. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,905
    Walter_Hulsebos likes this.
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    QFSW and Walter_Hulsebos like this.
  9. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    71
    Hi, is there any news about using MakeGenericType with Value types?
     
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,771
    See the comment just above, this should no longer be a problem in Unity 2022.1 and later.
     
    Walter_Hulsebos likes this.