title: HttpPost [FromForm] Always contains null
body: <p>I can't bind a [FromForm] in my IActionResult (ASP.NET Core 2) from C# desktop application.</p>
  
  <p><strong>In my C# desktop application</strong>, I have the following code:</p>
  
  <pre><code>private void SendStats ( object state )
  {
      double aCpu = ( ( double )AppDomain.CurrentDomain.MonitoringTotalProcessorTime.Ticks / this.totalRunningTime.Ticks ) * 100;
      double aMemory = ( double )AppDomain.MonitoringSurvivedProcessMemorySize / 1048576;
      string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  
      Stats anStats = new Stats( this.ID, aCpu, aMemory, version );
  
      using ( WebRequestHandler handler = new WebRequestHandler() )
      {
          using ( HttpClient client = new HttpClient( handler ) )
          {
              client.BaseAddress = new Uri( STATS_SERVER_URL );
              client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "application/json" ) );
  
              try
              {
                  var content = new StringContent( anStats.ToJSONString(), Encoding.UTF8, "application/x-www-form-urlencoded" );
  
                  using ( HttpResponseMessage response = client.PostAsync( STATS_SERVER_URL, content ).Result )
                  {
                      if ( response.IsSuccessStatusCode )
                      {
                          // Do nothing
                      }
                  } 
              }
              catch ( System.AggregateException ax )
              {
                  if ( !( ax.InnerException is HttpRequestException ) )
                      throw;
              }
          }
      }
  
      this.totalRunningTime += STATS_COLLECTION_PERIOD;
  }
  </code></pre>
  
  <p>My Stats class has:</p>
  
  <pre><code>using System.Runtime.Serialization;
  using System.Runtime.Serialization.Json;
  using System.IO;
  
  namespace MyNamespace.Stats
  {
      [DataContract]
      public class Stats
      {
          [DataMember]
          private string id;
  
          [DataMember]
          private double cpu;
  
          [DataMember]
          private double mem;
  
          [DataMember]
          private string version;
  
          public Stats ( string anId, double aCpu, double aMemory, string aVersion )
          {
              this.id = anId;
              this.cpu = aCpu;
              this.mem = aMemory;
              this.Version = aVersion;
          }
  
          public string ToJSONString ()
          {
               DataContractJsonSerializer aSerializer = new DataContractJsonSerializer ( typeof( Stats ) );
  
               using ( MemoryStream aMemStream = new MemoryStream() )
               {
                   aSerializer.WriteObject( aMemStream, this );
  
                   aMemStream.Position = 0;
  
                   using ( StreamReader aStreamReader = new StreamReader ( aMemStream ) )
                   {
                        return aStreamReader.ReadToEnd();
                   }
              }
         }
     }
  }
  </code></pre>
  
  <p><strong>In my ASP.NET Core 2 application</strong>, I have the following code:</p>
  
  <pre><code>[HttpPost("{productKey}")]
  [Consumes("application/x-www-form-urlencoded")]
  public IActionResult Create(string productKey, [FromForm] LegacyStatViewModel item)
  {
      NewUsageViewModel aNewUsageViewModel = new NewUsageViewModel
      {
          Cpu = Convert.ToInt32(item.Cpu),
          BinaryVersion = (item.Version == null ? "UNKNOWN" : item.Version),                
          LastConnection = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
          Memory = Convert.ToInt32(item.Mem),
          ProductKey = productKey               
      };
  
      _context.AspNetNewUsages.Add(aNewUsageViewModel);
      _context.SaveChanges();
  
      return CreatedAtRoute("GetStat", new { ProductKey = aNewUsageViewModel.ProductKey }, item);
  }
  </code></pre>
  
  <p>And finally, LegacyStatViewModel has the following code:</p>
  
  <pre><code>namespace MyApp.Models.StatsViewModels
  {
      public class LegacyStatViewModel
      {
          public string Id { get; set; }
  
          public double Cpu { get; set; }
  
          public double Mem { get; set; }
  
          public string Version { get; set; }
      }
  }
  </code></pre>
  
  <p>The IActionResult is called correcty from desktop application. ProductKey parameter has the expected value but all item fields are null or 0.</p>
  
  <p>Note: I can't modify Desktop application. </p>