I was following along with this API tutorial when I came upon an odd exception. It took a bit of guess-and-check testing, but I narrowed it down to only occur when the required keyword is added (below is the example model).
The tutorial lists the .NET 7.0 SDK in the prerequisites. From what I've found in the documentation, that should use C# 11 (which is when the required keyword was introduced). Is this an issue with the aspnet-codegenerator tool, the documentation, or my own misunderstanding?
Code:
namespace TodoApi.Models;
public class TodoItem
{
public long Id { get; set; }
public required string? Name { get; set; }
public bool IsComplete { get; set; }
}
Stack Trace:
$ dotnet aspnet-codegenerator controller -name TodoItemsController -async -api -m TodoItem -dc TodoContext -outDir Controllers
Building project ...
Finding the generator 'controller'...
Running the generator 'controller'...
Minimal hosting scenario!
Attempting to compile the application in memory.
Could not get the reflection type for DbContext : TodoApi.Models.TodoContext
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:09.75
Include provider and version information
Microsoft.VisualStudio.Web.CodeGeneration.Design version: 7.0.0
Target framework: .NET 7.0
Operating system: Windows 11
IDE: VS Code 1.82.2
I was following along with this API tutorial when I came upon an odd exception. It took a bit of guess-and-check testing, but I narrowed it down to only occur when the
required
keyword is added (below is the example model).The tutorial lists the .NET 7.0 SDK in the prerequisites. From what I've found in the documentation, that should use C# 11 (which is when the
required
keyword was introduced). Is this an issue with theaspnet-codegenerator
tool, the documentation, or my own misunderstanding?Code:
Stack Trace:
Include provider and version information
Microsoft.VisualStudio.Web.CodeGeneration.Design version: 7.0.0 Target framework: .NET 7.0 Operating system: Windows 11 IDE: VS Code 1.82.2