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,139 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. 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

  3. 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

  4. 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

  5. Mayer, Markus 1 Reputation point
    2022-10-03T07:07:17.103+00:00

    same problem here

    Building project ...  
    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)  
    RunTime 00:00:05.12  
    

    dotnet list package
    Project 'WebAuthentication' has the following package references
    [net6.0]:
    Top-level Package Requested Resolved

    Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 6.0.9 6.0.9
    Microsoft.AspNetCore.Identity.EntityFrameworkCore 6.0.9 6.0.9
    Microsoft.AspNetCore.Identity.UI 6.0.9 6.0.9
    Microsoft.EntityFrameworkCore.Design 6.0.9 6.0.9
    Microsoft.EntityFrameworkCore.SqlServer 6.0.9 6.0.9
    Microsoft.EntityFrameworkCore.Tools 6.0.9 6.0.9
    Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.10 6.0.10
    Serilog.AspNetCore 6.0.1 6.0.1
    Serilog.Settings.Configuration 3.4.0 3.4.0
    Serilog.Sinks.Console 4.1.0 4.1.0
    Serilog.Sinks.Debug 2.0.0 2.0.0
    Serilog.Sinks.File 5.0.0 5.0.0

    I already tried to scaffold with "-f" and "$env:codegen_trace=1", but I still get the same error without a hint. Plz help!

    0 comments No comments