5

Problem with scaffolding any controller using visual studio 2019 i get the error :
"there was an error running the selected code generator: 'The value -1 is outside the acceptable range of [0,2147483647]. Parameter name :value'"

Related links i have tried and still this issues persist

I tried the following :
1. (Error while generating view in Visual Studio 2019)
2. (Can't Add View from Controller in VS 2015 : "There was an error running the selected code generator")

Crate Duke
  • 98
  • 3
  • 10

6 Answers6

9

The issue is now fixed with the latest release of Visual Studio 2019: version 16.2.5: https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes#16.2.5

The issue would only to happen when:

  • you have the web.config file for your project open in Visual Studio.

So the workaround for was:

  • if you have the error, make sure you close the web.config file and you will be able to scaffold controllers.
Paul Cociuba
  • 116
  • 2
  • Per this [Link](https://developercommunity.visualstudio.com/content/problem/626755/error-running-the-selected-code-generator-value-1.html) [Recommended Solution] "We have determined that this issue only happens when the web.config file is open in the editor. Please close the web.config file & try the scaffolding scenario again. We will fix the issue when the web.config file is open but for now our recommended work-around is to close the web.config when trying the scaffolding scenario." – Crate Duke Aug 27 '19 at 21:54
1

I just found how to solve it for me after attempting many things.

My solution was to:

  • first navigate to the project folder with the solution and delete the packages folder.
    • Also delete .vs folder in the root of your solution
  • Then in your project folder delete the bin and obj folders.
  • Close your Visual Studio instance.
  • Next step is to navigate to your local user folder:

    Ex: C:\Users\[YourUserName]\AppData\Local\Microsoft\VisualStudio

You will see folders 16.0_ or 16.0_e9eb2d6b (Depending on your VS version). Navigate to the second folder 16.0_e9eb2d6b and delete the ComponentModelCache and Designer folders.

  • Close web.config file in the editor

  • Last step is to open your solution project in VisualStudio and click on Rebuild Solution from the Build tab.

Now try to create a View in your MVC project.

I hope this helps!

  • 1
    No hope it still did not work. I want to suspect it has something to do with the solution/project. When i created a new mvc project everything works. I might be tempted to create a new project and move files over one by one but i do not have the time and luxury. – Crate Duke Aug 07 '19 at 15:23
  • Try also updating your Visual Studio. There was a new version available. After I have updated I still had the problem and it was also for the certain project. So I deleted the Designer cache and the problem disappeared. – Konstantin Dinev Aug 08 '19 at 11:56
  • I am up to date with 16.2.1 , I noticed it is currently still under investigation from this [link](https://developercommunity.visualstudio.com/content/problem/626755/error-running-the-selected-code-generator-value-1.html) . I was working on an old project today and same issue came up .. I am doing everything manually for now. – Crate Duke Aug 08 '19 at 15:16
1

I ran into the same problem tomorrow, tried many manipulations found on different subjects, nothing worked. Finally, someone gave me a "solution" that let me continue my project, which simply is copy/paste any view...! Of course, you'll then have to hand code everything, but at least it'll let you add new views/controllers to your project. Hope this helps!

Jueverhard
  • 111
  • 11
1

Before Creating a View or Controller Make sure that your Web.config file is not open...

0

VS team is still working on this issue:

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

However, I have used VS 2017 to add the Control and I re-opened the solution with 2019 version and it seems to work

Druey
  • 1
  • 1
  • That's a neat trick, if you have both the IDE's available to you on the same machine. – abhi Aug 20 '19 at 16:11
0

This is what worked for me. Your mileage may vary.

1) Exit the solution from the IDE.
2) Delete the .vs folder (this may be hidden on your system)
3) Delete the packages folder under your solution.
4) Open the solution and perform Clean Solution from the IDE menu.
5) Restore the Nuget packages.
6) Try adding the new controller now.
abhi
  • 3,082
  • 6
  • 47
  • 73