title: Why can't C# compiler infer generic-type delegate from function signature?
body: <p>I'm working with a function that takes two functions as parameters, and returns a new composed one:</p>
  
  <pre><code>public static Action&lt;T&gt; Compose&lt;T&gt;(Action&lt;T&gt; first, Action second)
  {
      return new Action&lt;T&gt;(arg =&gt;
      {
          first(arg);
          second();
      });
  }
  </code></pre>
  
  <p>I've noticed that the compiler complains if I don't specify <code>T</code>, when sending it a static or member function (as opposed to an actual <code>Action&lt;T&gt;</code> object):</p>
  
  <pre><code>static void Main(string[] args)
  {
      // compiler error here
      var composed = Compose(Test, () =&gt; Console.WriteLine(" world"));
      composed("hello");
  
      Console.ReadLine();
  }
  
  public static void Test(string arg)
  {
      Console.Write(arg);
  }
  </code></pre>
  
  <p>The error message:</p>
  
  <blockquote>
    <p>The arguments for method 'ConsoleTest.Program.Compose(System.Action, System.Action)' cannot be inferred from the usage. Try specifying the type arguments explicitly.   </p>
  </blockquote>
  
  <p><strong>My question</strong>: Why can't the type argument be inferred here?  The signature of <code>Test</code> is known at compile time, is it not?  Is there really some function you could put in place of <code>Test</code>, that would cause its signature to be ambiguous?</p>
  
  <p><sub>Footnote: I know I can simply send <code>new Action&lt;string&gt;(Test)</code> instead of <code>Test</code> to <code>Compose</code> (as noted in <a href="https://stackoverflow.com/q/6090159/1001985">this question</a>) -- my question is "why", not "how can I do this".</sub></p>