title: Why can't my .NET 6 Minimal API deserialize POST body?
body: <p>I've build a very simple, vanilla minimal API with .NET 6. All I'm trying to do for now is prove that I can receive HTTP POST requests and log them. Hopefully if I can get this working I'll start doing something more interesting, but even this vanilla out of the box functionality isn't working.</p>
  <p>Some things I've tried:</p>
  <ul>
  <li>Changing my logMessage to a record</li>
  <li>Adding a default constructor to the logMessage</li>
  </ul>
  <p>My full code is posted below, can anyone see what is wrong with this? Or how to fix it?</p>
  <p>My minimal API:</p>
  <pre class="lang-cs prettyprint-override"><code>using Microsoft.AspNetCore.Http.Json;
  
  var builder = WebApplication.CreateBuilder(args);
  
  // Add services to the container.
  // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  builder.Services.AddEndpointsApiExplorer();
  builder.Services.AddSwaggerGen();
  
  // NOTE: tried the below but it made no difference. Commented back out.
  // builder.Services.Configure&lt;JsonOptions&gt;(options =&gt;
  // {
  //     options.SerializerOptions.IncludeFields = true;
  // });
  
  
  var app = builder.Build();
  
  // Configure the HTTP request pipeline.
  if (app.Environment.IsDevelopment())
  {
      app.UseSwagger();
      app.UseSwaggerUI();
  }
  
  app.UseHttpsRedirection();
  
  var summaries = new[]
  {
      &quot;Freezing&quot;, &quot;Bracing&quot;, &quot;Chilly&quot;, &quot;Cool&quot;, &quot;Mild&quot;, &quot;Warm&quot;, &quot;Balmy&quot;, &quot;Hot&quot;, &quot;Sweltering&quot;, &quot;Scorching&quot;
  };
  
  app.MapGet(&quot;/weatherforecast&quot;, () =&gt;
  {
      var forecast = Enumerable.Range(1, 5).Select(index =&gt;
         new WeatherForecast
         (
             DateTime.Now.AddDays(index),
             Random.Shared.Next(-20, 55),
             summaries[Random.Shared.Next(summaries.Length)]
         ))
          .ToArray();
      return forecast;
  })
  .WithName(&quot;GetWeatherForecast&quot;);
  
  app.MapPost(&quot;/&quot;, (logMessage message) =&gt; 
  {
      Console.WriteLine($&quot;[{DateTime.Now.ToShortDateString()}] Received message:&quot;);
      Console.WriteLine(message.LogMessage);
      return Results.Accepted;
  });
  
  app.Run(&quot;http://localhost:5025&quot;);
  
  internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary)
  {
      public int TemperatureF =&gt; 32 + (int)(TemperatureC / 0.5556);
  }
  
  public class logMessage
  {
      public string? LogMessage {get;set;}
  }
  </code></pre>
  <p>My post message (testing from Postman, but also tried sending from various other places):</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;LogMessage&quot;:&quot;test&quot;
  }
  </code></pre>
  <p>The result:</p>
  <pre><code>System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported. Path: $.Method.ReturnParameter.Member.DeclaringType.
   ---&gt; System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported.
     at System.Text.Json.Serialization.Converters.UnsupportedTypeConverter`1.Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
     at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T&amp; value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack&amp; state, Utf8JsonWriter writer)
     at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T&amp; value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack&amp; state, Utf8JsonWriter writer)
     at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T&amp; value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack&amp; state, Utf8JsonWriter writer)
     at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T&amp; value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack&amp; state, Utf8JsonWriter writer)
     at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T&amp; value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T&amp; value, JsonSerializerOptions options, WriteStack&amp; state)
     --- End of inner exception stack trace ---
     at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack&amp; state, NotSupportedException ex)
     at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T&amp; value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.Serialization.JsonConverter`1.WriteCoreAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.JsonSerializer.WriteCore[TValue](JsonConverter jsonConverter, Utf8JsonWriter writer, TValue&amp; value, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
     at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
     at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
     at Microsoft.AspNetCore.Http.HttpResponseJsonExtensions.WriteAsJsonAsyncSlow[TValue](Stream body, TValue value, JsonSerializerOptions options, CancellationToken cancellationToken)
     at Microsoft.AspNetCore.Http.RequestDelegateFactory.&lt;&gt;c__DisplayClass46_3.&lt;&lt;HandleRequestBodyAndCompileRequestDelegate&gt;b__2&gt;d.MoveNext()
  --- End of stack trace from previous location ---
     at Microsoft.AspNetCore.Routing.EndpointMiddleware.&lt;Invoke&gt;g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
     at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
  </code></pre>
  <p>Same result if I try from the Swagger page.</p>