title: dynamic in Task.Run
body: <p>I have a long running task with the same name in unrelated classes. I was trying to have this code in common method using dynamic.
  I am getting following error </p>
  
  <blockquote>
    <p>Microsoft.CSharp.RuntimeBinder.RuntimeBinderException was unhandled by user code
     Message=Cannot implicitly convert type 'void' to 'object'</p>
  </blockquote>
  
  <p>I tried to isolate the code to the following</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          MainAsync();
          Console.ReadKey();
      }
      static async void MainAsync()
      {
          var classA = new ClassA();
          var classB = new ClassB();
          await RunTask1(classA);
          await RunTask1(classB);
          await RunTask(classA);
          await RunTask(classB);
      }
      static async Task RunTask(dynamic val)
      {
          await Task.Run(() =&gt; val.CommonLongRunningTask());
      }
      static async Task RunTask1(ClassA val)
      {
          await Task.Run(() =&gt; val.CommonLongRunningTask());
      }
      static async Task RunTask1(ClassB val)
      {
          await Task.Run(() =&gt; val.CommonLongRunningTask());
      }
  }
  internal class ClassA
  {
      public void CommonLongRunningTask()
      {
          Console.WriteLine("Class A CommonLongRunningTask");
      }
  }
  internal class ClassB
  {
      public void CommonLongRunningTask()
      {
          Console.WriteLine("Class B CommonLongRunningTask");
      }
  }
  </code></pre>
  
  <p>If I pass the object itself (RunTask1) instead of dynamic it works. I am trying to understand what is happening when I am passing in dynamic.</p>