title: Multiple types [FromBody] on same method .net core web api
body: <p>I have a controller with one POST method, which will receive an xml string which can be of 2 types. Eg:</p>
  
  <pre><code>[HttpPost("postObj")]
      public async Task&lt;IActionResult&gt; postObj([FromBody]firstClass data)
      {
          if (data != null)...
  </code></pre>
  
  <p>I would like to be able to bind to multiple types on the same route ([HttpPost("postObj")])
  So that I can receive on <a href="http://127.0.0.1:5000/api/postObj" rel="noreferrer">http://127.0.0.1:5000/api/postObj</a> with firstClass xml in the body, or secondClass xml in the body, and act accordingly.</p>
  
  <p>I tried making another method with the same route but different type like:</p>
  
  <pre><code>    [HttpPost("postObj")]
      public async Task&lt;IActionResult&gt; postObj([FromBody]secondClass data)
      {
          if (data != null)...
  </code></pre>
  
  <p>but I get "Request matched multiple actions resulting in ambiguity", as expected.</p>
  
  <p>I tried reading the body and doing a check then serializing the xml to the respective object, but that drastically reduced the performance.</p>
  
  <p>I am expecting up to 100 requests per second, and binding using FromBody is giving me that, but manually reading the body and serializing gives me only about 15.</p>
  
  <p>How can I achieve that?</p>