question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When JArray is used on response / request as datatype, generator fails with System.InvalidOperationException

See original GitHub issue

Version: <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />

Response class:

    public class FooResponse
    {
        public JArray RowData { get; set; } // = new JArray();
    }

Controller:

        [HttpPost("/v1/x/")]
        public ActionResult<FooResponse> GetFoo()
        {
            return Ok(new FooResponse());
        }

When swagger document is requested it fails with:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLML4VELUGHU", Request id "0HLML4VELUGHU:00000002": An unhandled exception was thrown by the application.
System.InvalidOperationException: TODO:
   at Swashbuckle.AspNetCore.SwaggerGen.ChainableSchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ObjectSchemaGenerator.GeneratePropertySchema(JsonProperty jsonProperty, Object[] attributes, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ObjectSchemaGenerator.GenerateSchemaFor(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ChainableSchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ReferencedSchemaGenerator.GenerateSchemaFor(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ChainableSchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateResponseMediaType(Type type, SchemaRepository schemaRespository)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateResponse(String statusCode, ApiResponseType apiResponseType, IEnumerable`1 methodAttributes, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateResponses(ApiDescription apiDescription, IEnumerable`1 methodAttributes, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
domaindrivendevcommented, May 16, 2019

Should be resolved by 6f9e899cfe46e8d99a12e42e378e7c03693dd1c2

0reactions
ipzKellyRcommented, Dec 11, 2019

I am still seeing an issue where Swagger does not work if you have a parameter that contains a JArray property.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Deserialize JSON to array giving System. ...
Your problem can occur when Deserialize() cannot create a new instance of the object your are deserializing. In order to make Deserialize() ...
Read more >
Migrate from Newtonsoft.Json to System.Text.Json - .NET
Supported by built-in functionality. Getting similar behavior from System.Text.Json may require the use of an attribute or global option.
Read more >
Working with System.Text.Json in C# - CodeProject
As the Converter is strongly typed, if you try to use the converter on the wrong data type, a System.InvalidOperationException will be thrown...
Read more >
Cannot cast type json to integer
JArray ' The thing is it was working. (millisecond precision) In this section, we will use the CAST function to convert the data...
Read more >
SSIS Productivity Pack
Fixed: CDM source component may make repetitive failed service calls to retrieve the list of partitions when the specified path does not exist...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found