title: Unable to retrieve the runtime generic context for 'System.Collections.Generic.List
body: <p>I've created a class that inherits from <a href="https://docs.microsoft.com/es-es/dotnet/api/system.collections.generic.list-1?view=net-6.0" rel="nofollow noreferrer">List</a> to be used on my Unity-firebase project porpouses.</p>
  <pre><code>using System.Collections.Generic;
  
  public class FirestoreList&lt;FirestoreData, PlainData&gt; : List&lt;FirestoreData&gt;, IConvertToPlainData&lt;List&lt;PlainData&gt;&gt;
      where FirestoreData : IConvertToPlainData&lt;PlainData&gt;
      where PlainData : IConvertToFirestore&lt;FirestoreData&gt;
  {
      public FirestoreList() : base() { }
      public FirestoreList(List&lt;PlainData&gt; plainDataList) &lt;-- this is the 8th line
      {
          this.Clear();
          foreach (PlainData plainData in plainDataList)
          {
              this.Add(plainData.ToFirestoreData());
          }
      }
  
      public List&lt;PlainData&gt; ToPlainData()
      {
          List&lt;PlainData&gt; convertedPlainDataList = new List&lt;PlainData&gt;();
          if (this.Count &gt; 0)
          {
              foreach (FirestoreData firestoreData in this)
              {
                  convertedPlainDataList.Add(firestoreData.ToPlainData());
              }
          }
  
          return convertedPlainDataList;
      }
  }
  </code></pre>
  <p>The interfaces are the following ones (basically functioning as a Serialize/Deserialize):</p>
  <pre><code>public interface IConvertToPlainData&lt;T&gt;
  {
      T ToPlainData();
  }
  
  public interface IConvertToFirestore&lt;T&gt;
  {
      T ToFirestoreData();
  }
  </code></pre>
  <p>This code works on the Editor, on runtime etc, but when I try to build using IL2CPP (cause I'm targeting mobile stores) the following error on the build appears:</p>
  <pre><code>IL2CPP error for method 'System.Void FirestoreList`2::.ctor(System.Collections.Generic.List`1&lt;PlainData&gt;)' in FirestoreList.cs:8
  Additional information: Unable to retrieve the runtime generic context for 'System.Collections.Generic.List`1&lt;PlainData&gt;'.
  </code></pre>
  <p>I don't understand the error message, and I didn't find any similar references on google, all that I have is this <a href="https://docs.unity3d.com/2021.2/Documentation/Manual/ScriptingRestrictions.html?_ga=2.58874349.1571481587.1637692423-1751818090.1485189056" rel="nofollow noreferrer">link</a> about Unity and IL2CPP ScriptingRestrictions :(</p>
  <p>Can someone help me or at least point me to the answer? Thanks!</p>
  <p><strong>EDIT:</strong>
  An example of the classes that I use to show the generic parameter that I use to instantiate FirestoreList:</p>
  <pre><code>[Serializable]
  public class User : IConvertToFirestore&lt;User_FirestoreData&gt;
  {
    [SerializeField] public List&lt;User&gt; usersList = new List&lt;User&gt;();
  
    public User_FirestoreData ToFirestoreData()
    {
      User_FirestoreData userFire = new User_FirestoreData()
      {
        usersList = new FirestoreList&lt;User_FirestoreData, User&gt;(this.usersList)
      };
  
      return userFire;
    }
  
  }
  
  [FirestoreData]
  public class User_FirestoreData : IConvertToPlainData&lt;User&gt;
  {
    [FirestoreProperty] public FirestoreList&lt;User_FirestoreData, User&gt; usersList { get; set; }
  
    public User ToPlainData()
    {
      User user = new User()
      {
        usersList = this.usersList.ToPlainData(),
      };
      return user;
    }
  
  }
  </code></pre>
  <p><strong>EDIT2:</strong>
  My thoughs are that when I'm using <code>this.usersList.ToPlainData()</code> there's no specification of what is <code>FirestoreData</code> and <code>PlainData</code>, so the compiler can't know what cast to do (or something similar).</p>
  <p>For the moment the only solution have been to remove the FirestoreList class and implement a couple of extension methods for List like these ones:</p>
  <pre><code>public static List&lt;PlainData&gt; ToPlainData&lt;PlainData, FirestoreData&gt;(this List&lt;FirestoreData&gt; list) where FirestoreData : IConvertToPlainData&lt;PlainData&gt; where PlainData : IConvertToFirestore&lt;FirestoreData&gt;
  {
      List&lt;PlainData&gt; convertedPlainDataList = new List&lt;PlainData&gt;();
      if (list.Count &gt; 0)
      {
          foreach (FirestoreData firestoreData in list)
          {
              convertedPlainDataList.Add(firestoreData.ToPlainData());
          }
      }
  
      return convertedPlainDataList;
  }
  
  public static List&lt;FirestoreData&gt; ToFirestoreData&lt;FirestoreData, PlainData&gt;(this List&lt;PlainData&gt; list) where FirestoreData : IConvertToPlainData&lt;PlainData&gt; where PlainData : IConvertToFirestore&lt;FirestoreData&gt;
  {
      List&lt;FirestoreData&gt; convertedFirestoreDataList = new List&lt;FirestoreData&gt;();
      if (list.Count &gt; 0)
      {
          foreach (PlainData plainData in list)
          {
              convertedFirestoreDataList.Add(plainData.ToFirestoreData());
          }
      }
  
      return convertedFirestoreDataList;
  }
  </code></pre>
  <p>As you are forced to call it like this: <code>this.charactersList.ToPlainData&lt;User, User_FirestoreData&gt;()</code> seems like there is no problem with the JIT or AOT.</p>