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,180 questions
{count} votes

9 answers

Sort by: Most helpful
  1. AMG 10 Reputation points
    2023-04-10T13:43:07.3833333+00:00

    Still have the same problem even with latest nuget packages and on .NET 7. Is there any way to get a more detailed error message?

    Project 'Portal' has the following package references
       [net7.0]: 
       Top-level Package                                           Requested   Resolved
       > DevExpress.Blazor                                         22.2.5      22.2.5  
       > DevExpress.Blazor.Server.WebAssembly                      22.2.5      22.2.5
       > Microsoft.AspNetCore.Diagnostics                          2.2.0       2.2.0   
       > Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore      7.0.4       7.0.4   
       > Microsoft.AspNetCore.Identity.EntityFrameworkCore         7.0.4       7.0.4   
       > Microsoft.AspNetCore.Identity.UI                          7.0.4       7.0.4   
       > Microsoft.EntityFrameworkCore                             7.0.4       7.0.4   
       > Microsoft.EntityFrameworkCore.Sqlite                      7.0.4       7.0.4   
       > Microsoft.EntityFrameworkCore.SqlServer                   7.0.4       7.0.4   
       > Microsoft.EntityFrameworkCore.Tools                       7.0.4       7.0.4   
       > Microsoft.VisualStudio.Web.CodeGeneration.Design          7.0.5       7.0.5   
    
    
    Finding the generator 'identity'...
    Running the generator 'identity'...
    No database provider found. Using 'SqlServer' by default for new DbContext creation!  (Even though I have selected this in menu, it says that there is no provider found)
    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)
    
    
    0 comments No comments

  2. Robert _ 0 Reputation points
    2023-05-06T12:08:42.63+00:00

    I have the same problem with .NET 7, blazor server app with Individual Accounts.

    I can however create a new blazor server with individual accounts and scaffold without problems...
    I can copy the scaffolded files (login and register) into the original project and I can do changes to the HTML but I can no longer login or register if I do this.

    Next time I create a Blazor server or MVC, I'm going to scaffold immediately to avoid this crap...

    0 comments No comments

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Greg Cartwright 0 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.

    0 comments No comments