Skip to content

OpenAPI Throws System.ArgumentNullException Inside Docker #56309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
NixFey opened this issue Jun 19, 2024 · 6 comments
Closed
1 task done

OpenAPI Throws System.ArgumentNullException Inside Docker #56309

NixFey opened this issue Jun 19, 2024 · 6 comments
Labels
feature-openapi Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Comments

@NixFey
Copy link

NixFey commented Jun 19, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When spinning up a new Web project, then building and running in Docker, an error is thrown when attempting to go to the OpenAPI endpoint. This bug does not occur when running locally outside of a container.

Expected Behavior

The OpenAPI document is returned, like it is when running locally in Debug/Run mode.

Steps To Reproduce

https://github.com/evanlihou/Net9OpenApiBugTest

Exceptions (if any)

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HN4FUDA16P3M", Request id "0HN4FUDA16P3M:00000001": An unhandled exception was thrown by the application.
      System.ArgumentNullException: Value cannot be null. (Parameter 'type')
         at System.Text.Json.ThrowHelper.ThrowArgumentNullException(String parameterName)
         at System.Text.Json.JsonSerializerOptions.GetTypeInfo(Type type)
         at JsonSchemaMapper.JsonSchemaMapper.MapJsonSchemaCore(GenerationState& state, JsonTypeInfo typeInfo, Type parentType, JsonPropertyInfo parentPropertyInfo, ParameterInfo parentParameterInfo, String description, Boolean isNullableReferenceType, Boolean isNullableOfTElement, JsonConverter customConverter, Nullable`1 customNumberHandling, Boolean hasDefaultValue, JsonNode defaultValue, Type parentPolymorphicType, Nullable`1 typeDiscriminator)
         at JsonSchemaMapper.JsonSchemaMapper.GetJsonSchema(JsonSerializerOptions options, Type type, JsonSchemaMapperConfiguration configuration)
         at Microsoft.AspNetCore.OpenApi.OpenApiComponentService.CreateSchema(ValueTuple`2 key)
         at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
         at Microsoft.AspNetCore.OpenApi.OpenApiComponentService.GetOrCreateSchema(Type type, ApiParameterDescription parameterDescription)
         at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetResponse(ApiDescription apiDescription, Int32 statusCode, ApiResponseType apiResponseType)
         at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetResponses(ApiDescription description)
         at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetOperation(ApiDescription description, HashSet`1 capturedTags)
         at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetOperations(IGrouping`2 descriptions, HashSet`1 capturedTags)
         at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetOpenApiPaths(HashSet`1 capturedTags)
         at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetOpenApiDocumentAsync(CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Builder.OpenApiEndpointRouteBuilderExtensions.<>c__DisplayClass0_0.<<MapOpenApi>b__0>d.MoveNext()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Http.Generated.<GeneratedRouteBuilderExtensions_g>F56B68D2B55B5B7B373BA2E4796D897848BC0F04A969B1AF6260183E8B9E0BAF2__GeneratedRouteBuilderExtensionsCore.<>c__DisplayClass2_0.<<MapGet0>g__RequestHandler|5>d.MoveNext()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

.NET Version

9.0.0-preview.6.24307.2

Anything else?

Using latest stable version of JetBrains Rider on macOS

Using nightly 9.0-preview Docker images as base

dotnet --info inside of container

Host:
  Version:      9.0.0-preview.6.24307.2
  Architecture: arm64
  Commit:       static
  RID:          linux-arm64

.NET SDKs installed:
  No SDKs were found.

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.6.24309.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.6.24307.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
@ghost ghost added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jun 19, 2024
@captainsafia
Copy link
Member

@evanlihou Thanks for reporting this issue! This is an interesting bug.

The stack trace that you've identified (and that I was able to see using your repro) is coming from the prototype implementation of the JsonSchemaExporter APIs that we used in initial iterations of our implementation and appears to be unique to enumerable types. I was not able to reproduce this with plain old WeatherForecast.

In recent versions of the build (9.0.0-preview.6.24324.2 and above), I'm not able to repro the same issue so I assume that this was a transient bug with the prototype that was resolved in the final implementation.

Can you verify that using a newer version of the package from the nightly feed resolves the issue for you as well?

@captainsafia captainsafia added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Jun 27, 2024
@NixFey
Copy link
Author

NixFey commented Jun 27, 2024

I just pulled the latest nightly container image and it's still running 9.0.0-preview.6.24321.8 (which the error is still occurring on). I'll give it another day or two for the build you mentioned to get incorporated, then try a rebuild

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Jun 27, 2024
@NixFey
Copy link
Author

NixFey commented Jun 28, 2024

Still able to repro inside of Docker with the following runtime after clearing out old images and re-pulling. If there's anything else I can do to help either make this issue more reproducible or to prove it's a non-issue, I'm happy to!

$ dotnet --info

Host:
  Version:      9.0.0-preview.6.24321.8
  Architecture: arm64
  Commit:       static
  RID:          linux-arm64

.NET SDKs installed:
  No SDKs were found.

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.6.24324.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.6.24321.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

@captainsafia
Copy link
Member

@evanlihou Thanks for giving this another try!

I realize I should've been clearer with my instructions. The build I was referring to earlier was the build of the Microsoft.AspNetCore.OpenApi package, not the .NET runtime.

Can you try out the changes in this branch to make sure we're on the same page? The run.sh script is what I used to build and run the container.

Here's the output I see from that:

http://127.0.0.1:8080/openapi/v1.json
/ 20240703074318
// http://127.0.0.1:8080/openapi/v1.json

{
  "openapi": "3.0.1",
  "info": {
    "title": "Net9OpenApiBugTest | v1",
    "version": "1.0.0"
  },
  "paths": {
    "/weatherforecast": {
      "get": {
        "tags": [
          "Net9OpenApiBugTest"
        ],
        "operationId": "GetWeatherForecast",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "required": [
                      "date",
                      "temperatureC",
                      "summary"
                    ],
                    "type": "object",
                    "properties": {
                      "date": {
                        "type": "string",
                        "format": "date"
                      },
                      "temperatureC": {
                        "type": "integer",
                        "format": "int32"
                      },
                      "summary": {
                        "type": "string",
                        "nullable": true
                      },
                      "temperatureF": {
                        "type": "integer",
                        "format": "int32"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    
  },
  "tags": [
    {
      "name": "Net9OpenApiBugTest"
    }
  ]
}

@captainsafia captainsafia added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Jul 3, 2024
Copy link
Contributor

Hi @evanlihou. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@NixFey
Copy link
Author

NixFey commented Jul 4, 2024

Thank you for putting together that fork. I just pulled it down and yep everything seems to be working well now, so I'll close out this issue and wait for those changes to make their way to the standard Nuget feed. Have a good holiday if you're celebrating!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-openapi Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

No branches or pull requests

3 participants