373 questions
1
vote
1
answer
3k
views
ASP.NET Core Web API - InvalidOperationException: Body was inferred but the method does not allow inferred body parameters
I created an ASP.NET Core Web API project with the default Visual Studio template, disabling the configure for https checkmark and whenever I am trying to run my application, I get this error shown ...
1
vote
0
answers
214
views
How do I secure a minimal API project called from Blazor client-side using bearer token?
I am used to using Blazor server-side, where (basically) all the action happens on the server, so you don't need to expose APIs that need securing.
I'm now exploring client-side Blazor (ie WASM), and ...
0
votes
1
answer
197
views
How to log application insights and read configuration in common class library in minimal api net7
I'm new to minimal api net7 .I want to log the application insights when any exception raise and read the configuration from app.settings.json in another common library. Here I'm using the concept of ...
0
votes
1
answer
1k
views
Minimal API authentication based getting data
I am setting up an authentication and authorization for my minimal API (.Net 7) using this tutorial: https://www.telerik.com/blogs/authorization-authentication-minimal-apis
I have never done this ...
0
votes
1
answer
44
views
How to write a RestFUL client to receive a Results.File?
The minimal API was written as below. How can I write a client (something like a proxy) to download the file and then forward the content to another WebAPI server?
app.MapGet("/myapi", () =&...
4
votes
1
answer
1k
views
.NET 7/8 How do I provide a description/summary on a Group with Minimap APIs?
I am adding a group of minimal APIs like this:
var myapi = app.MapGroup("myapi").WithTags("My API").WithOpenApi();
// and then
myapi .MapGet($"/", GetAllStuff).WithName(&...
0
votes
0
answers
459
views
Mock "Negotiate" authentication in .NET 6/7
I've been following the official documentation to mock the authorization service, and it seems to be working perfectly when using JWTBearer authentication, but it returns a 500 status code when I try ...
1
vote
1
answer
2k
views
How to get current endpoint name into the .NET Minimal API filter?
I'm currently working with a minimal API in C# and I'm using various extension methods to configure endpoints. In my specific case, I have an endpoint defined like this:
app.MapGet("/...
4
votes
2
answers
3k
views
This .NET 7 minimal API always returns 200
I'm quite new to the concept of a minimal API, but the documentation seems quite clear. You only have to use Results or TypedResults to return the response code you want.
So I made a very basic try:
...
0
votes
1
answer
796
views
Uploading File and data with minimal API
I'm new to web development generally but I'm creating a file repository that uses minimal APIs. I need to store customer files in silos so need to pass a TenantID in to choose the storage location. It ...
1
vote
2
answers
607
views
Validate ASP.NET Core Minimal APIs at startup
I am using ASP.NET Core Minimal APIs with .NET 8.
I have an application that adds some endpoints.
One of these endpoints is not valid, but the app starts normaly:
info: Microsoft.Hosting.Lifetime[14]
...
3
votes
1
answer
1k
views
Minimal API Service not injected using .NET Carter
I´m creating an API in .NET using Carter. I have this Module Defined:
public class VariationsModule : EntityModule<Variation>
{
public VariationsModule()
{
...
0
votes
2
answers
860
views
ASP.Net Core API writing files to filestore
I'm developing a document repository using a .net core api project targeted for .net 7 and with minimal API. As a stopgap the uploaded files will be persisted as files to locally attached server ...
-1
votes
2
answers
415
views
Publish custom endpoint address in ASP.NET Core minimal API
I have 6 API methods as you can see:
app.MapGet("/api/customer-money/", ([FromServices] IMediator mediator, string customerIsin)
=> mediator.Send(new GetMoneyQuery(customerIsin)));
...
2
votes
2
answers
869
views
ASP.NET Core Mimal APIs - AddEndpointFilter throws InvalidOperationException
AddEndpointFilter throws exception shown below in .NET 7 (7.0.102) at program start under debug. Used IDE Microsoft Visual Studio Professional 2022 (64-bit) - Current Version 17.6.3
System....
1
vote
1
answer
102
views
Default challenge scheme isn't working with RouteGroups?
I have a Route Group for several endpoints:
internal class EmployeeRouteGroup : RouteGroup
{
/// <inheritdoc />
protected override string Prefix => "employees";
/// <...
15
votes
1
answer
13k
views
How to make enum serialization default to string in minimal API endpoints and Swagger?
I'm working with .NET minimal APIs and have encountered a problem with JSON serialization/deserialization behavior for enums. Despite my attempts to change the behavior to use strings instead of ...
5
votes
1
answer
3k
views
IExceptionFilter in minimal .NET 7 API
In my ASP.NET Core app I was registering an IExceptionFilter to globally catch exceptions and replace the Result returned to the client. I'm now switching to the minimal API way of doing things, but I'...
0
votes
2
answers
6k
views
How can i get base url of a c# minimal api application?
i have a minimal api application and i would like to return a path to file, most of the answers i found are for controller based APIs that use the Request to get the url from.
0
votes
1
answer
268
views
Why is my image not showing up in a minimal API image uploader?
I am making a very simple minimal api image uploader, and i cannot for the life of me figure out why the image will not show post upload. It launches properly, allows me to upload the image, saves the ...
3
votes
2
answers
4k
views
Swagger for Minimal API
I'm trying to use minimal API in my project. the problem I'm facing is that the traditional Controllers are in a way that swagger generates a seperate section for each and every Controller. but I can'...
0
votes
0
answers
336
views
HTTP error with swagger ui with minimal API image uploader
I am attempting to use minimal api to develop an image uploader. I have the program.cs file code debugged and it launches to a webpage with an http 404 error. This is the entirety of the code.
using ...
2
votes
1
answer
124
views
CS8602 error stopping me from running Minimal API image uploader
I am trying to build an image uploader in a .NET 6 Minimal API. I believe that i have all the proper components but I am utterly confused on the problem that I am having. One specific line in the code ...
0
votes
1
answer
2k
views
Trouble upgrading IEndpointRouteBuilder method from .Net6 to .Net8
The following method defines my endpoints and worked fine in .Net 6. I am upgrading this app now to .Net 8 before I get to far along since that will be standard in a few months.
public static void ...
1
vote
1
answer
728
views
Writing & testing a PatchAsJsonAsync request in a .NET 7.0 Minimal API
Writing the Implementation
Let's pretend I have a Person object:
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; ...
1
vote
0
answers
2k
views
Minimal API swagger doesn't generate/discover anything when async
Building a test app with .NET 7 minimal api swagger for learning purposes. Mostly a default project at this point. What has me confused is if I convert what you see below to not be async then Swagger ...
1
vote
1
answer
1k
views
.NET 7 minimal API request timeout
I found this in .NET 8 (prerelease) but I can't use it due to company policy.
https://learn.microsoft.com/en-us/aspnet/core/performance/timeouts?view=aspnetcore-8.0&viewFallbackFrom=aspnetcore-7.0
...
8
votes
2
answers
21k
views
How do I get the incoming request body and the outgoing response body in ASP.NET Core middleware?
I'm writing some middleware for an ASP.NET Core 7 minimal API project.
At this stage, I would just like to be able to read the request body being sent in, and then the response body that is being sent ...
3
votes
2
answers
2k
views
.NET Core 6 minimal API with OpenApi - validate request against OpenApi schema
I'm working on a minimal API in .NET Core 6 with OpenApi support.
I have a Resolution model defined like this:
using System.ComponentModel.DataAnnotations;
public struct Resolution
{
[Required, ...
0
votes
1
answer
123
views
ArgumentException Object serialized to String. JObject instance expected
How do I modify my exception middleware to still continue execution of this code below:
public async Task<MessageResponseModel> TransferSecondModelData()
{
//get the untransferred records ...
1
vote
1
answer
124
views
Convert the model's fields as Dictionary in another model's field
I have this model:
namespace SomeApp.Models
{
public class FirstModel
{
public int uid { get; set; }
public string? id { get; set; }
public string? firstname { get; set;...
5
votes
1
answer
9k
views
How to add example responses in Swagger in a ASP .NET minimal API?
I would like to add examples of answers for my endpoints in my minimal API in .NET 7.
I have already found several interesting resources but none of them work in the context of a minimal API:
https://...
0
votes
0
answers
153
views
${aspnet-request-posted-body} with appsetings based configuration
I was reading whole topics on StackOverflow and NLog's wiki but nothing works for me..
Maybe I am unable to see something and someone could see it.
I have a minimal API and I would like to log my ...
0
votes
1
answer
2k
views
Bearer error="invalid_token", error_description="The signature key was not found" using auth0
I am having an issue with authenticating my webapi(.net core 7 minimal api) requests:I can successfully generate a token but when I pass it over to another endpoint that requires authentication I get ...
-1
votes
1
answer
898
views
Why is this .NET 7 minimal api complaining that it cannot model bind from a body? It thinks it should model bind from a querystring
Why is the .NET 7 minimal api throwing a run time error for the following POST endpoint?
Required parameter "Guid fooId" was not provided from query string.
It is trying to model bind to a ...
0
votes
1
answer
918
views
Multidimensional array parameter binding with ASP.NET Minimal API
I have quite a few places where multidimensional arrays of varying lengths are used as query parameters.
With controllers a request with to /multi?vals[0][0]=5&vals[0][1]=6&vals[1][0]=6&...
0
votes
1
answer
899
views
return a Tuple from minimal API
I'm trying to return a Tuple in a minimal API, it boils down to this:
app.MapPost("/colorkeyrect", () => server.ColorkeyRect());
public (int x, int y, int w, int h) ColorkeyRect()
{
...
2
votes
1
answer
2k
views
.NET Minimal API: how to map all route and all verb in the same handler?
Our team maintains a huge repository containing multiple applications that have been started more than 10 years ago. The strategy at that time was to create classes that implement IHttpHandler and the ...
0
votes
1
answer
533
views
GetEndpoint from Middleware returns 405 HTTP Method Not Supported when launching from integration test
I'm using an ASP.NET minimal API which works fine when launching normally, but when I try to reuse the Program class from my integration tests there is one endpoint that fails in a custom middleware.
...
1
vote
2
answers
4k
views
In ASP.NET Core minimal API, how can you get the route name?
I would like to test the routing of a minimal API WebApplication. How can I get the route name, given a HttpRequestMessage?
var builder = WebApplication.CreateBuilder(args);
builder.Services....
2
votes
1
answer
3k
views
ASP.NET Core 7 Minimal API - Swagger doesn't start
We have a minimal API application, and whenever we start the app, we get a "Localhost not found" error instead of getting the Swagger interface. If we add the /swagger to the end of the URL, ...
2
votes
1
answer
2k
views
File size limit on .NET 7 Minimal Web API
So I have a little problem here, I wanted to port a .NET Core 2.1 web API to an ASP.NET Core web API with .NET 7.
I need to be able to upload files larger than 50MB (up to 300MB, since it will include ...
3
votes
2
answers
2k
views
How to return chunked text/plain content from Web API using minimal API
Using an ASP.NET Core 6 Web API written in C# with minimal API, I would like to return a stream of data without first loading the data into memory. In my case this is JSONL (JSON lines) data that is ...
3
votes
1
answer
2k
views
Streaming data using HotChocolate GraphQl for .NET project - all results at once instead of one by one problem
I'm using C#, .NET7 minimal API and HotChocolate GraphQl. I'm trying to setup graphQl simple query endpoint which will be able to return stream like this:
public async IAsyncEnumerable<string> ...
3
votes
1
answer
715
views
What is the correct lifetime for classes used to organize Minimal Api endpoints and should I resolve them in CreateScope()?
I am still learning and afraid of captive dependency (a dependency with an incorrectly configured lifetime). Consider the following code snippet and the full code is given at the bottom.
My objectives:...
1
vote
2
answers
291
views
Minimal Web Api Not Returning Desired Result
I have created a minimal ASP.NET Core Web API project in Visual Studio. And then deploying this to Azure Web App Service to be able to 'GET' results remotely. Locally, the /weatherforecast sample data ...
1
vote
2
answers
180
views
Error still occurs even after registering the required dependency, what is wrong?
The following code simulates the problem. I do register the dependency but errors still occur.
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
builder.Services....
2
votes
1
answer
849
views
Register minimal API IEndpointRouteBuilder with Scrutor
I have created an Interface.
public interface IEndpoint
{
RouteGroupBuilder MapRoutes(IEndpointRouteBuilder rotues);
}
And it's implementation like this.
public class TodoApi : IEndpoint
{
...
5
votes
1
answer
2k
views
Asp.NET Core 7.0 Minimal API: OpenAPI how to specify correct DateOnly type representation
In minimal API I define this endpoint that accepts DateOnly parameter:
app.MapGet("/info", (DateOnly date) => $"{date.ToString("yyyy-MM")}";
By default swagger json ...
-1
votes
1
answer
353
views
Trouble with json reponse parsing to object in unity
I am sending data from dot net minimal API :
app.MapGet("/mytableDistinct", async ([FromServices] ShipmentDbContext dbContext) =>
{
IQueryable<long> query = dbContext.MyTables....