Skip to content
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

Minmal .NET API - Delegate 'RequestDelegate' does not take 0 arguments #34390

Closed
mindingdata opened this issue Jul 15, 2021 · 2 comments
Closed
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Milestone

Comments

@mindingdata
Copy link

I'm trying to test out creating a minimal .NET Core API, with a very simple structure. e.g. :

using Microsoft.AspNetCore.Builder;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/hello", () => "Hello, World!");

app.Run();

I seem to get the following error :

Delegate 'RequestDelegate' does not take 0 arguments

I checked for other issues inside this repo, and the only similar mention was when the cast was removed from the delegate here : #33393

Because previously you had to cast to a Func like so (And this does get my code compiling without errors).

app.MapGet("/", (Func<string>)(() => "Hello World!"));

If I run my code using dotnet run, the code actually runs fine and generates a response. So I'm thinking it could be more about the tooling I'm using, but I'm not sure where.

I have the latest .NET Core 6 - Preview 6 SDK :

.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.6.21355.2
 Commit:    7f8e0d76c0

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\

Host (useful for support):
  Version: 6.0.0-preview.6.21352.12
  Commit:  770d630b28

My VS Code version is :

Version: 1.58.2 (system setup)
Commit: c3f126316369cd610563c75b1b1725e0679adfb3
Date: 2021-07-14T22:10:15.214Z
Electron: 12.0.13
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Windows_NT x64 10.0.19042

My VS Code C# extension version is 1.23.13

My Visual Studio 2019 is version 16.10.3 (But not preview, which could be the issue)

So again :

  • Code will build fine with dotnet build
  • Code will run find using dotnet run OR running via Visual Studio
  • Code will display an output warning/error in both Visual Studio and VS Code that Delegate 'RequestDelegate' does not take 0 arguments
@DamianEdwards
Copy link
Member

Indeed I think the issue is your tooling has an older version of the compiler which doesn't have the improvements to delegate casting. If you try it in the VS2019 preview or VS2022 preview it should work.

@davidfowl davidfowl added this to the Discussions milestone Jul 15, 2021
@davidfowl davidfowl added the feature-minimal-actions Controller-like actions for endpoint routing label Jul 15, 2021
@davidfowl davidfowl added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Jul 30, 2021
@ghost ghost added the Status: Resolved label Jul 30, 2021
@ghost
Copy link

ghost commented Jul 31, 2021

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Jul 31, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 30, 2021
@amcasey amcasey added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jun 2, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

5 participants