There was an error running the selected code generator: 'Object reference not set to an instance of an object.' Error?

我的未来我决定 提交于 2019-12-10 12:38:35

问题


I have tried all the solution like repairing the VS 2013 but no use. when you create a controller by right clicking on the Controller folder and you add the controller, then you right click in the Action of the newly created controller and select Add View, it happens right then, when I try to create a view. Its not a new project, its an existing project.


回答1:


I had this issue on my VS2017 and i solved it by doing this:
Go to C:\Users\username\AppData\Local\Microsoft\VisualStudio\15.0_7fca0c70 and you will see a folder named ComponentModelCache just renamed it like _ComponentModelCache or anything else,visual studio will create this folder again.
One thing to notice under VisualStudio folder name 15.0_7fca0c70 can be differenct it depends on your VS version. Now you are good to Go. Hope it helps somebody.




回答2:


For me the error had to do with the fact that I had a project in my solution that was a .NET Core project library and was referenced in the project that housed the DbContext.

Removing - or I guess changing the type - the .NET core library resolved the issue




回答3:


I have the same error in Visual Studio 2017 I fix it by this solution :

1 - if you use any database , must be install all drivers (I mean Nugget packages and etc...) (I use MySql db so i must I first install MySql installer and install MySql,Data,EntityFramWorkCore)

2 - I Update My Visual Studio with Visual Studio Installer (your must be search visual studio installer in start and run it next update (don't need to add any new component or codes only select Update Button ) )

It work for me , I hope this will be help you




回答4:


Deleting the .vs folder inside the solution directory worked for me.




回答5:


This Error is related to Entity Framework Data Model .. for solution Perform these Steps...

  1. Delete your Entity Framework Data Model.
  2. Again Regenerate the Model from Database Design.
  3. then Rebuild the Solution ... and Enjoy Coding .



回答6:


I have the same error, I just removed only read permission in the folder where is the web project




回答7:


Try installing the Windows Management Framework:

https://www.microsoft.com/en-us/download/details.aspx?id=34595

Restart the PC after installing.




回答8:


Or maybe like me you didn't notice the 'Data context class' field was blank. Oops. If so, simply select your data context class and try again.

There really should be a better error for this scenario.




回答9:


Removed the error by starting a whole new project because I had initially referenced a Class Library that housed the data access and business logic code for my project.




回答10:


Just change your ConnectionString in Web.Config file From

<add name="xxx" connectionString="Data Source=xxx;initial catalog=xxx;Persist Security Info=True;User ID=xxxx;Password=xxxx;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

To

<add name="xxx" connectionString="metadata=res://*/EFMOdel.csdl|res://*/EFMOdel.ssdl|res://*/EFMOdel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxxx;initial catalog=xxxx;persist security info=True;user id=xxxx;password=xxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />



回答11:


I have the same error in vs2017 on windows10, pls try to run vs as admin, hope it'll work for you too.




回答12:


Tried all the following answers with no luck:

  • Solution Clean
  • Deleting old migrations
  • Close and reopen Visual Studio
  • Delete Visual Studio temp Components folder

This one worked:

  • Uninstalled the package (Microsoft.VisualStudio.Web.CodeGeneration.Design) and re-installed it from Package Manager Console.

My environment: Visual Studio 2019 - Razor Pages - .Net Code 2.2 - Windows 10




回答13:


Although I had not noticed right away that my ability to add Controllers ceased when I added another project to the solution, I eventually caught on that this was a repeatable cause for my disruption. This is what worked for me:

  • In addition to the .Net Web App project where I was adding Controllers, I had added another project to the solution- this causes the problem for me.
  • I unloaded the new project and then tried the Add Controller step again. This time it worked.
  • I then reloaded the new project and continued to work

It took me a couple of hours to diagnose and solve this. Maybe it helps someone else to not spin wheels this long!




回答14:


Instead of renaming, I left DefaultController then renamed it after it was created.



来源:https://stackoverflow.com/questions/39127199/there-was-an-error-running-the-selected-code-generator-object-reference-not-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!