Visual Studio debugger crashes when selecting IFormFile in Swagger UI
09:43 09 Sep 2025

I'm running an ASP.NET API in Visual Studio. I have an endpoint to upload a file using IFormFile.

[HttpPost(Name = "AddDocument")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task AddDocument([FromForm] AddDocumentRequest file, CancellationToken token)
{
    await _documentService.AddDocument(file.File, token)
}

The parameter model :

public class AddDocumentRequest
{
    [Required]
    public required IFormFile File { get; set; }
}

The endpoint works fine if i run the endpoint without debugging. It also works when i use Postman.

If I run the API with debugging and try to select a file in the Swagger UI form, the API immediately exits before the endpoint is even hit without any errors in output window.

The swagger code in program.cs :

builder.Services.AddSwaggerGen(options =>
{
    options.SwaggerDoc("default", new OpenApiInfo { Title = "Public endpoints", Version = "v1" });
    options.IncludeXmlComments(Path.Combine(System.AppContext.BaseDirectory, "SwaggerAnnotations.xml"));
    options.IncludeXmlComments(Path.Combine(System.AppContext.BaseDirectory, "SwaggerAnnotationsBL.xml"));

    options.DocInclusionPredicate((docName, apiDesc) =>
    {
        var categories = apiDesc.ActionDescriptor
            .EndpointMetadata.OfType()
            .FirstOrDefault()?.Categories;

        return docName switch
        {
            "default" => true,
            _ => false
        };
    });

    options.AddSecurityRequirement(new OpenApiSecurityRequirement
    {
        {
            new OpenApiSecurityScheme
            {
                Reference = new OpenApiReference
                {
                    Type = ReferenceType.SecurityScheme,
                    Id = "Bearer"
                }
            },
            Array.Empty()
        }
    });
    options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
    {
        Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
        Name = "Authorization",
        In = ParameterLocation.Header,
        Scheme = "Bearer",
        Type = SecuritySchemeType.Http
    });


    options.SchemaFilter();
    options.DocumentFilter();
    options.SchemaFilter();
});


app.UseSwaggerUI(options =>
{
    options.SwaggerEndpoint("/swagger/default/swagger.json", "Public Endpoints");
});
app.UseSwagger();
app.MapOpenApi();

Any ideas what is causing this?

c# asp.net-core debugging swagger swagger-ui