Skip to content

System.Collections.Generic.KeyNotFoundException: The given key 'CONNECT' was not present in the dictionary.  #2740

@voroninp

Description

@voroninp

I want to create a WebSocket endpoint.
If I use just [Route] attribute, Swagger throws an error.

Currently ASP.NET does not provide [HttpConnect] attribute., so I had to declare it myself:

public sealed class HttpConnectAttribute : HttpMethodAttribute
{
    private static readonly string[] _httpMethods = ["CONNECT"];

    public HttpConnectAttribute() : base(_httpMethods)
    {
    }

    public HttpConnectAttribute(string template) : base(_httpMethods, template)
    {
    }
}

And after I applied it to the method, swagger throws:

System.Collections.Generic.KeyNotFoundException: The given key 'CONNECT' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   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.GetSwaggerDocumentWithoutFilters(String documentName, String host, String basePath)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerAsync(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.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

I had to exclude that endpoint from the docs: [ApiExplorerSettings(IgnoreApi = true)]

  1. How do I add support for 'CONNECT' to Swagger docs?
  2. Is there any WebSocket support at all?

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions