Note that there are some explanatory texts on larger screens.

plurals
  1. POAmbiguous Invocation on Generic ContinueWith
    primarykey
    data
    text
    <p>I'm writing a simple C# console application that uses Asynchronous Tasks and Entity Framework (with the intent to run it under Linux (RHEL) with Mono, but that's a whole other challenge). Note that I'm targeting .NET 4.0, so I'm using <code>.ContinueWith()</code> instead of <code>await</code>.</p> <p>This, plus the EF DB model of a Northwind Database, is the entirety of the application:</p> <pre class="lang-cs prettyprint-override"><code>using System; using System.Linq; using System.Threading.Tasks; namespace MonoEF { class Program { private static Model.NorthwindEntities _db = new Model.NorthwindEntities(); static void Main(string[] args) { try { GetCustomerNamesAsync().ContinueWith(t =&gt; { if (t.IsFaulted) Console.WriteLine(t.Exception.Flatten.ToString); else if (t.IsCompleted) foreach (string result in t.Result) Console.WriteLine(result); }); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } private static Task&lt;string[]&gt; GetCustomerNamesAsync() { return Task.Factory.StartNew(() =&gt; (from c in _db.Customers select c.ContactName).Distinct().ToArray()); } } } </code></pre> <p>The problem is I'm getting the following error at the <code>.ContinueWith()</code>:</p> <pre><code>Ambiguous Invocation: System.Threading.Tasks.Task.ContinueWith(System.Action&lt;System.Threading.Tasks.Task&lt;string[]&gt;&gt;) (in class Task&lt;string[]&gt;) System.Threading.Tasks.Task.ContinueWith(System.Action&lt;System.Threading.Tasks.Task&gt;) (in class Task) match </code></pre> <p>To me, the invocation shouldn't be ambiguous, the compiler should prefer the generic Task over the non-generic Task, especially as it's the output of <code>GetCustomerNamesAsync()</code>. However, as a VB.NET developer, I'm probably relying on <code>Option Infer</code> in this situation.</p> <p>How would I go about explicitly letting the compiler know which invocation I want it to use in C#?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload