title: Why can't Mono support generic interface instantiation with AOT?
body: <p>The Mono documentation has a code example about <a href="http://www.mono-project.com/docs/advanced/aot/" rel="noreferrer">full AOT</a> not supporting generic interface instantiation:</p>
  
  <pre><code>interface IFoo&lt;T&gt; {
  ... 
      void SomeMethod();
  }
  </code></pre>
  
  <p>It says:</p>
  
  <blockquote>
    <p>Since Mono has no way of determining from the static analysis what method will implement the interface <code>IFoo&lt;int&gt;.SomeMethod</code> this particular pattern is not supported." </p>
  </blockquote>
  
  <p>So I think the compiler can't work with this method under type inference. But I still can't understand the underlying reason about the full AOT limitation. </p>
  
  <p>There is still a similar problem with the <a href="http://docs.unity3d.com/Manual/ScriptingRestrictions.html" rel="noreferrer">Unity AOT script restrictions</a>. In the following code:</p>
  
  <pre><code>using UnityEngine;
  using System;
  
  public class AOTProblemExample : MonoBehaviour, IReceiver 
  {
      public enum AnyEnum {
          Zero,
          One,
      }
  
      void Start() {
          // Subtle trigger: The type of manager *must* be
          // IManager, not Manager, to trigger the AOT problem.
          IManager manager = new Manager();
          manager.SendMessage(this, AnyEnum.Zero);
      }
  
      public void OnMessage&lt;T&gt;(T value) {
          Debug.LogFormat("Message value: {0}", value);
      }
  }
  
  public class Manager : IManager {
      public void SendMessage&lt;T&gt;(IReceiver target, T value) {
          target.OnMessage(value);
      }
  }
  
  public interface IReceiver {
      void OnMessage&lt;T&gt;(T value);
  }
  
  public interface IManager {
      void SendMessage&lt;T&gt;(IReceiver target, T value);
  }
  </code></pre>
  
  <p>I am confused by this:</p>
  
  <blockquote>
    <p>The AOT compiler <strong>does not realize that it should generate code for the generic method <code>OnMessage</code> with a <code>T</code> of <code>AnyEnum</code></strong>, so it blissfully continues, skipping this method. When that method is called, and the runtime can’t find the proper code to execute, it gives up with this error message.</p>
  </blockquote>
  
  <p>Why does the AOT not know the type when the JIT can infer the type? Can anyone offer a detailed answer?</p>