title: JsonResult(object) causes "The collection type 'Newtonsoft.Json.Linq.JToken' is not supported."
body: <p>I upgraded an existing ASP.NET Core 2.2 project to 3.0. I have a method that returns JSON which worked in 2.2, but in 3.0, it causes "The collection type 'Newtonsoft.Json.Linq.JToken' is not supported." at the return.</p>
  
  <pre><code>[HttpGet()]
  public async Task&lt;JsonResult&gt; Get()
  {
      var res = some class object in a third-party library;
      return new JsonResult(res);
  }
  </code></pre>
  
  <p>I have searched Google and found that Microsoft has replaced Newtonsoft Json to <code>System.Text.Json</code>, but I have not explicitly used Newtonsoft Json. In the project's "Frameworks", I could see the Newtonsoft Json, and I removed it and the <code>using Newtonsoft.Json.Linq</code> statements, but the result was the same. How not to use Newtonsoft Json?</p>
  
  <p>The error message is: </p>
  
  <pre><code>System.NotSupportedException: The collection type 'Newtonsoft.Json.Linq.JToken' is not supported.
     at System.Text.Json.JsonClassInfo.GetElementType(Type propertyType, Type parentType, MemberInfo memberInfo, JsonSerializerOptions options)
     at System.Text.Json.JsonClassInfo.CreateProperty(Type declaredPropertyType, Type runtimePropertyType, Type implementedPropertyType, PropertyInfo propertyInfo, Type parentClassType, JsonConverter converter, JsonSerializerOptions options)
     at System.Text.Json.JsonClassInfo.AddProperty(Type propertyType, PropertyInfo propertyInfo, Type classType, JsonSerializerOptions options)
     at System.Text.Json.JsonClassInfo.AddPolicyProperty(Type propertyType, JsonSerializerOptions options)
     at System.Text.Json.JsonClassInfo..ctor(Type type, JsonSerializerOptions options)
     at System.Text.Json.JsonSerializerOptions.GetOrAddClass(Type classType)
     at System.Text.Json.JsonPropertyInfo.get_ElementClassInfo()
     at System.Text.Json.JsonSerializer.HandleObject(JsonPropertyInfo jsonPropertyInfo, JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack&amp; state)
     at System.Text.Json.JsonSerializer.WriteObject(JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack&amp; state)
     at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack&amp; state)
     at System.Text.Json.JsonSerializer.WriteAsyncCore(Stream utf8Json, Object value, Type inputType, JsonSerializerOptions options, CancellationToken cancellationToken)
     at Microsoft.AspNetCore.Mvc.Infrastructure.SystemTextJsonResultExecutor.ExecuteAsync(ActionContext context, JsonResult result)
     at Microsoft.AspNetCore.Mvc.Infrastructure.SystemTextJsonResultExecutor.ExecuteAsync(ActionContext context, JsonResult result)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeResultAsync&gt;g__Logged|21_0(ResourceInvoker invoker, IActionResult result)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeNextResultFilterAsync&gt;g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
  --- End of stack trace from previous location where exception was thrown ---
     at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeFilterPipelineAsync&gt;g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeAsync&gt;g__Logged|17_1(ResourceInvoker invoker)
     at Microsoft.AspNetCore.Routing.EndpointMiddleware.&lt;Invoke&gt;g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
     at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
  </code></pre>
  
  <hr>
  
  <p>PS: I have tried it with other types and got some similar exception messages for collection types. With that, I searched Google and found <a href="https://github.com/dotnet/corefx/issues/40120" rel="noreferrer">this open issue on .NET Core's GitHub</a>. It seems like <code>System.Text.JSon</code> currently does not support collection types fully, and a workaround is just use the old Newtonsoft Json.</p>