I'm trying to generate a controller in Dotnet ASP.NET Core by following the tutorial on https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model?view=aspnetcore-8.0&tabs=visual-studio-code, but when I use the command dotnet aspnet-codegenerator controller -name MoviesController -m Movie -dc MvcMovie.Data.MvcMovieContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries --databaseProvider sqlite
, I get this error message:
startIndex cannot be larger than length of string. (Parameter 'startIndex')
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)
Here is information about my environment:
using System.ComponentModel.DataAnnotations;
namespace MvcMovie.Models;
public class Movie
{
public int Id { get; set; }
public string? Title { get; set; }
[DataType(DataType.Date)]
public DateTime ReleaseDate { get; set; }
public string? Genre { get; set; }
public decimal Price { get; set; }
}
D:\MvcMovie> dotnet --info
.NET SDK:
Version: 8.0.401
Commit: 811edcc344
Workload version: 8.0.400-manifests.b6724b7a
MSBuild version: 17.11.4+37eb419ad
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.401\
.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.
Host:
Version: 8.0.8
Architecture: x64
Commit: 08338fcaa5
.NET SDKs installed:
8.0.401 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
PS D:\MvcMovie> dotnet tool list -g
Package Id Version Commands
-------------------------------------------------------------------------
dotnet-aspnet-codegenerator 8.0.5 dotnet-aspnet-codegenerator
dotnet-ef 8.0.8 dotnet-ef
dotnetsay 2.1.7 dotnetsay
D:\Users\User\Documents\selfreading\datacentric\MvcMovie> dotnet list package
Project 'MvcMovie' has the following package references
[net8.0]:
Top-level Package Requested Resolved
> Microsoft.EntityFrameworkCore.Design 8.0.8 8.0.8
> Microsoft.EntityFrameworkCore.SQLite 8.0.8 8.0.8
> Microsoft.EntityFrameworkCore.SqlServer 8.0.8 8.0.8
> Microsoft.EntityFrameworkCore.Tools 8.0.8 8.0.8
> Microsoft.VisualStudio.Web.CodeGeneration.Design 8.0.5 8.0.5
I'm not sure what the issue is. Please help.
this is an Information of person who also have the same issue: https://stackoverflow.com/questions/74543076/dotnet-aspnet-codegenerator-controller-error-startindex-cannot-be-larger-than-le