16

I am working on an ASP.NET MVC project and so far I had no problems with scaffolding any type of items until now.

Every time I want to create a new controller or view, I get the following error message:

There was an error running the selected code generator: 'The value -1 is outside the acceptable range of [0,2147483647]. Parameter name :value'

This issue only arises in the project that I'm currently working on as I tried creating a new controller in another project and it worked flawlessly.

I already tried the solution to delete the ComponentModelCache folder and rebuilding the project but the problem still persists.
My Visual Studio 2019 is also up to date.

EDIT: Pulling the project from git source control on another PC and restoring the packages fixed the issue for me. You probably don't have to do it from another computer, just try deleting the project and restoring it from remote.

EDIT 2: Creating a second view and the same problem is back again...

Superhdninja
  • 179
  • 1
  • 1
  • 7
  • 2
    It could be a nuget package, extension, or corrupted Visual Studio installation. Try removing and re-adding your nuget dependencies one by one and see if the problem persists after each remove. Also, update visual studio and your extensions. – Jesse de Wit Aug 10 '19 at 13:32

14 Answers14

15

I fixed this by unloading and reloading the project

juagicre
  • 1,065
  • 30
  • 42
Mahogany
  • 509
  • 4
  • 17
7

You just need to - delete ".vs" folder from your solution directory. In summary only the deleting of the .vs folder is what has worked for me.

On reopening VS2019 16.2.3 - I can now add in Controllers and Views without seeing this error.

Found it from Microsoft Developer Community site: https://developercommunity.visualstudio.com/content/problem/626755/error-running-the-selected-code-generator-value-1.html?childToView=684261#comment-684261

code-generator-solution

uvcreation
  • 91
  • 1
  • 9
  • According to the linked issue, having the web.config file open while trying to run the code generator is what caused the issue. It is fixed in 16.2.4. – Bakanekobrain Dec 04 '19 at 18:41
5

This issue has been resolved in Visual Studio 2019 version 16.2.4. The release notes are available here:

https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes#16.2.4

Mike
  • 91
  • 1
  • 7
4

One of the possibility is if your web.config file is open then this error might appear. Try closing the web.config file and then add a View.

You can also reach out to this website for more reference: Error Running the Selected Code Generate Value

Hope this helps.

Rohan Rao
  • 2,505
  • 3
  • 19
  • 39
2

I was able to fix this by replacing the web project with a new one.

-I renamed the project like project_old folder and removed it from solution. -Added a new project to the solution by right click and add project -Created the old controllers and everything with copying from old project files -Updated nuget packages and deleted old project files

Clean Solution -> Rebuild Solution and voilla

1

i fix it, deleting the .vs folder, re opening the project, and clenning the solution

  • this answer is not helpful. please use following guideline for your answer. https://stackoverflow.com/help/how-to-answer – Ramin Ahmadi Aug 20 '19 at 22:38
1

Close all documents, and try again to create new controller. It works for me in Visual Studio 2019 asp.net MVC but I don't know why

Alexander Ushakov
  • 5,139
  • 3
  • 27
  • 50
0

I was able to fix this by manually deleting the BIN and OBJ folders for my projects. Running Clean in Visual Studio did not work.

Delubear
  • 56
  • 5
0

I was getting this error - as my project is a git repository, I ran git clean -xfd on it, then rebuilt it and was able to add a controller when I tried again.

0

try both any one will work either of them.

1.Just delete .vs folder in project solution.
2.If above fix does not work.,close your web.config file if it is opened.
sai
  • 239
  • 1
  • 3
  • 7
0

I tried it all and finally found a solution that worked, this issue only happens when the web.config file is open in the editor. Hope this help.

Credits : Vijay Ramakrishnan [MSFT]
https://developercommunity.visualstudio.com/content/problem/626755/error-running-the-selected-code-generator-value-1.html

Viral Parmar
  • 112
  • 1
  • 3
0

I fixed this by matching the version of "Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" to the rest.

Replaced everything that was 5.0.9 with 5.0.2 and it worked.

Christian Rios
  • 417
  • 5
  • 15
-3

Go Back to VS 2017 and it will work just fine

-4

just use vs15. In many regards vs19 is still beta...