I am writing a simple console application in C # that uses Asynchronous Tasks and Entity Framework (with the intention of running it under Linux (RHEL) using Mono, but this is another problem). Note that I am targeting .NET 4.0, so I use .ContinueWith() instead of await .
This, plus the Northwind database EF DB model, is a complete application:
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 => { 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<string[]> GetCustomerNamesAsync() { return Task.Factory.StartNew(() => (from c in _db.Customers select c.ContactName).Distinct().ToArray()); } } }
The problem is that I get the following error in .ContinueWith() :
Ambiguous Invocation: System.Threading.Tasks.Task.ContinueWith(System.Action<System.Threading.Tasks.Task<string[]>>) (in class Task<string[]>) System.Threading.Tasks.Task.ContinueWith(System.Action<System.Threading.Tasks.Task>) (in class Task) match
For me, the call should not be ambiguous, the compiler should prefer a general task for a non-general task, especially since it outputs GetCustomerNamesAsync() . However, as a VB.NET developer, I probably rely on Option Infer in this situation.
How can I explicitly tell the compiler which call I want to use in C #?
source share