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

Error in API scaffolder when model type uses the required keyword #2133

Closed
DamianEdwards opened this issue Dec 1, 2022 · 1 comment
Closed
Labels

Comments

@DamianEdwards
Copy link
Member

Found using latest Visual Studio INT PREVIEW or PREVIEW build.

  1. Create a new ASP.NET Core Web API project targeting .NET 7 without controllers (aka Minimal APIs)
  2. Add the following model type declaration to Program.cs (note the required keyword on the Title property):
    public class Todo
    {
        public int Id { get; set; }
        public required string Title { get; set; }
        public bool IsComplete { get; set; }
    }
  3. Invoke the "API with read/write endpoints, Entity Framework" scaffolder via the "Add Scaffolded Item" project context menu
    • Select the Todo type as the model class
    • Select to create a new endpoints class with the default name
    • Select to create a new data context class with the default name
    • Leave other options at their default values
  4. The following error dialog is displayed:
    image
    ---------------------------
    Microsoft Visual Studio
    ---------------------------
    Error
    
    There was an error running the selected code generator:
    
    'There was an error creating a DbContext :C:\Users\damia\source\repos\WebApplication109\WebApplication109\Program.cs(31,21): error CS1519: Invalid token 'string' in class, record, struct, or interface member declaration'
    ---------------------------
    OK   
    ---------------------------
    
@deepchoudhery
Copy link
Member

Fixed, verified in VS 17.4.3 and VS 17.5 Preview 2 (newer 7.0.1 packages)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants