Identity scaffolding in .net core 6.0 gives error message "Length cannot be less than zero."

Jonathan Feucht 26 Reputation points
2022-07-18T13:50:12.27+00:00

Hello,

I've been trying to scaffold various Identity pages, however I keep getting an error dialog which says "There was an error running the selected code generator: 'Length cannot be less than zero. (Parameter 'length')'". 221876-param-length-zero.png.

In the code generation log, it gives a stack trace:

Finding the generator 'identity'...  
Running the generator 'identity'...  
Length cannot be less than zero. (Parameter 'length')  
   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)  

I'm running version 6.0.7 for the CodeGeneration package.

221699-nuget-packages.png

So is this a bug with the CodeGeneration package? Is there something else I should probably look into for debugging this? How can I get more information for the cause of this error dialog?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,209 questions
{count} votes

9 answers

Sort by: Most helpful
  1. MarcoA 6 Reputation points
    2022-08-05T06:09:10.427+00:00

    I have the same situation. in asp.net 6 application
    I used class program with Main in the program.cs file
    "...
    public class Program
    {

    [Obsolete]  
    public static void Main()  //string[] args  
    {  
    

    .."

    I have seen that in new projects the program.cs file does not contain the class program and the Main.
    It may have some connection?

    1 person found this answer helpful.
    0 comments No comments

  2. Greg Cartwright 5 Reputation points
    2023-07-01T19:16:30.5233333+00:00

    Marco hit the nail on the head with this for me, I commented out the namespace, program class definition and main method from my program.cs file, confirmed that my project still ran, and I was able to scaffold the razor identity pages I was looking for instead of getting the zero length error.

    //namespace ChatBotTemplate
    //{
    //    public class Program
    //    {
    //        public static async Task Main(string[] args)
    //        {
    				var builder = WebApplication.CreateBuilder(args);
    				//More code
    				var app = builder.Build();
    //        }
    //	  }
    //}
    

    Cheers Marco.

    1 person found this answer helpful.

  3. Alexander Malyshkin 1 Reputation point
    2022-08-08T06:48:41.093+00:00

    I have the same issue! 228977-scaffolding-issue.png

    0 comments No comments

  4. Atif Husain 1 Reputation point
    2022-08-27T06:29:26.973+00:00

    Hi, I have the exact same issue. It comes on Visual Studios for Mac... it works find when done from scratch in Visual Studio on windows even in .NET 6.

    Anyone was able to find a solution?

    0 comments No comments

  5. Ace 1 Reputation point
    2022-09-22T03:48:22.817+00:00

    After updating all nuget packages, errors were gone and was able to scaffold was able to generate all Identity files. Hope this helps.

    0 comments No comments