title: Create Expression for new Action<T> where T is unknown at compile time
body: <p>Edit2: removed a load of gubbins + bounty.</p>
  
  <p>I have deconstructed an  expression for a message bus in the hope of reconstructing it and invoking it in a slightly different manner. The serialization and deserialization is successful and I am able to create instances of most of what I need.</p>
  
  <pre><code>//Deconstruct
  Expression&lt;Func&lt;T, Task&gt;&gt; expression
  
  proxy =&gt; proxy.serviceMethod(arg);
  </code></pre>
  
  <p>I need to create the syntax below. T is an interface to a WCF service. This expression will be passed to a service invoker where it's internal ChannelFactory will pass it into this method. </p>
  
  <pre><code>//Reconstruct this as expression so I can pass it as a parameter
  var myAction = new Action&lt;T&gt;(proxy =&gt; {
      proxy.serviceMethod((SomeType)SomeParameter));
  });
  
  // to pass to this method
  serviceInvokerTMethod.Invoke(serviceInvokerTInstance, new object[] { myAction });
  </code></pre>
  
  <p>What I have:</p>
  
  <pre><code>//I think i'm nearly there I can create the inner call and assign 
  //the correct parameter, but I can't seem to figure out how to wrap it in an 
  // new Action&lt;serviceT&gt; { my other expressions... }
  
  // Types
  var serviceT = Type.GetType(workOutMessage.interfaceType);
  var actionT = typeof(Action&lt;&gt;).MakeGenericType(serviceT);
  var envelopeT = Type.GetType(workOutMessage.methodArgTypes[0]);
  
  // ServiceInvoker&lt;T&gt; Instantiation - Works
  var serviceInvokerT = typeof(HubServiceInvoker&lt;&gt;).MakeGenericType(serviceT);
  var serviceInvokerTMethod = serviceInvokerT.GetMethod("InvokeService");
  var serviceInvokerTInstance = Activator.CreateInstance(serviceInvokerT, client.Id, "password", clientCert, serviceCert);
  
  // Expression Type Params
  var serviceTParam = Expression.Parameter(serviceT, "proxy");
  var envelopeParam = Expression.Parameter(envelopeT, "envelope");
  
  var envAssign = Expression.Assign(envelopeParam, Expression.Constant(workOutMessage.methodArgs[0]));
  var methodCall = Expression.Call(serviceTParam, serviceT.GetMethod(workOutMessage.methodName), envelopeParam);
  
  // var lambda = ...                                               
  // make new Action&lt;serviceT&gt; myAction = { proxy =&gt; proxy.someMethod(someParameter); };
  
  serviceInvokerTMethod.Invoke(serviceInvokerTInstance, new object[] { lambda.Compile() });  
  </code></pre>
  
  <p>Edit: The Service Invoker Method I pass this into to, to try and give the problem better context.</p>
  
  <pre><code>public void InvokeService(Action&lt;T&gt; handler)
      {
          T proxy = channelFactory.CreateChannel();
          ((IClientChannel)proxy).Faulted += ChannelFaulted;
  
          ICommunicationObject obj2 = (ICommunicationObject)proxy;
          try
          {
              using (new OperationContextScope((IContextChannel)proxy))
              {
                  handler.Invoke(proxy);
              }
          }
          finally
          {
              try
              {
                  if (obj2.State != CommunicationState.Faulted)
                  {
                      obj2.Close();
                  }
              }
              catch
              {
                  obj2.Abort();
              }
          }
      }
  </code></pre>