asp.net-mvc 无法在 VS 2015 中从控制器添加视图:“运行所选代码生成器时出错”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34992599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't Add View from Controller in VS 2015 : "There was an error running the selected code generator"
提问by AymenDaoudi
I'm following a video tutorial where I'm required to create an empty ASP.NET WebApplication with MVC, using Visual Studio 2015, being new to ASP.NET world, I'm following step by step.
我正在关注一个视频教程,我需要在其中创建一个空的ASP.NET Web应用程序MVC,使用Visual Studio 2015ASP.NET 世界的新手,我正在逐步遵循。
I got my project created well, next step adding a View from an existing Controller, I got hit by a messagebox error saying :
我很好地创建了我的项目,下一步从现有的视图添加一个视图Controller,我遇到了一个消息框错误说:
Error :
There was an error running the selected code generator: 'Invalid pointer (Exception from HRESULT:0x80004003(E_POINTER))'
错误:
运行所选代码生成器时出错:“无效指针(来自 HRESULT 的异常:0x80004003(E_POINTER))”
I Googled the problem, found similar issues, but none leaded to a clear solution, some similar problems where issued by anterior version of VisualStudio, but as I said none with a clear solution.
我用谷歌搜索了这个问题,发现了类似的问题,但没有一个明确的解决方案,一些类似的问题是由 VisualStudio 的早期版本发布的,但正如我所说的没有一个明确的解决方案。
To clarify what I experienced, here's what I've done step by step :
为了澄清我的经历,以下是我逐步完成的工作:
Chosen a ASP.NET Web Application :
选择一个 ASP.NET Web 应用程序:
Chosen Empty Template with MVC checked :
选中 MVC 选中的空模板:
Tried to Add Viewfrom a Controller :
试图Add View从控制器:
Some settings ...
一些设置...
The Error :
错误 :
What's causing this problem and What is the solution for it ?
是什么导致了这个问题,它的解决方案是什么?
Update :
更新 :
It turns out that even by trying to add the View manually I get the same error, adding a view is all ways impossible !
事实证明,即使尝试手动添加视图,我也会遇到同样的错误,添加视图完全不可能!
回答by longday
Try clearing the ComponentModelCache, the cache will rebuild next time VS is launched.
尝试清除 ComponentModelCache,缓存将在下次启动 VS 时重建。
- Close Visual Studio
- Delete everything in this folder C:\Users\
[your users name]\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache - Restart Visual Studio
- 关闭 Visual Studio
- 删除此文件夹中的所有内容 C:\Users
[your users name]\\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache - 重新启动 Visual Studio
14.0 is for visual studio 2015. This will work for other versions also.
14.0 适用于 Visual Studio 2015。这也适用于其他版本。
回答by lucky.expert
I had this issue with a different error message "-1 is outs the bounds of.."
我遇到了一个不同的错误消息“-1 超出了..”的问题。
The only thing that worked for me, was to remove the project from the solution by right clicking the project and selecting 'Remove'. Then right click the solution, Add Existing Project, and selecting the project to reload it into the solution.
唯一对我有用的是通过右键单击项目并选择“删除”从解决方案中删除该项目。然后右键单击解决方案,添加现有项目,然后选择项目以将其重新加载到解决方案中。
After reloading the project, I can now add views again.
重新加载项目后,我现在可以再次添加视图。
回答by sh.alawneh
Follow these steps to add a view in a different way than the typical way:
按照以下步骤以不同于典型方式的方式添加视图:
- 1) Open Visual studio.
- 2) Create/open your project.
- 3) Go to Solution Explorer.
- 4) Right click on the target folder.
- 5) From the list, choose Add.
- 6) From the child list, choose MVC View Page (Razor)or MVC View Page with layout (Razor).
- 7) If you select the second choice from the previous step, you should choose a layout page for your view from the pop up window.
- 8) That's it!
- 1) 打开视觉工作室。
- 2) 创建/打开您的项目。
- 3) 转到解决方案资源管理器。
- 4) 右键单击目标文件夹。
- 5) 从列表中选择添加。
- 6) 从子列表中,选择MVC View Page (Razor)或 MVC View Page with layout (Razor)。
- 7) 如果您选择上一步中的第二个选项,您应该从弹出窗口中为您的视图选择一个布局页面。
- 8)就是这样!
If you cannot open the view that you are created, simply right click on the view file, choose Open with, and select HTML (web forms) editorthen okay.
如果您无法打开您创建的视图,只需右键单击视图文件,选择打开方式,然后选择HTML(网络表单)编辑器,然后就可以了。
回答by Maksym Labutin
I have the same error but in VS 2017 when I create a controller. I did it in the same way as @sh.alawneh wrote. Also, I tried to do what @longday wrote. But It didn't work. Then I tried in another way:
我有同样的错误,但在 VS 2017 中创建控制器时。我的做法与@sh.alawneh 所写的相同。另外,我尝试做@longday 写的事情。但它没有用。然后我尝试了另一种方式:
- Right click on the target folder.
- From the list, choose Add => New Item.
- 右键单击目标文件夹。
- 从列表中,选择添加 => 新项目。
There I choose a new controller and it works fine.
在那里我选择了一个新的控制器,它工作正常。
Maybe I'll help someone.
也许我会帮助某人。
回答by sGermosen
Lets assume you are using a datacontext in a DLL, well, it was my case, and I dont know why I have the same error that you describe, I solve it creating a datacontextLocal on the backend project. then I pass the Dbset to the correct datacontext and delete the local (you can let it there if you want, can be helpfull in the future
假设您在 DLL 中使用 datacontext,好吧,这是我的情况,我不知道为什么我遇到了您描述的相同错误,我解决了它在后端项目上创建 datacontextLocal 的问题。然后我将 Dbset 传递给正确的数据上下文并删除本地(如果需要,您可以将其放在那里,将来会有所帮助
if you ready are using it in local datacontext, create a new one and then pass the Dbset to the correct one
如果您准备在本地数据上下文中使用它,请创建一个新的,然后将 Dbset 传递给正确的
回答by MOHAMMAD OMAR
Right-click on the project under the solution and click unload Project,
右键单击解决方案下的项目,然后单击卸载项目,
you will see that the project is unloaded, so now re right-click on it and press load project
您将看到该项目已卸载,因此现在重新右键单击它并按加载项目
then try to add your controller
然后尝试添加您的控制器
回答by Adam Hey
Deleting the .vs folder inside the solution directory worked for me.
删除解决方案目录中的 .vs 文件夹对我有用。
回答by Hoodlum
I am working on a Core 3 app and had this issue pop up when adding a controller. I figured out that the Microsoft.VisualStudio.Web.CodeGeneration.Design package was updated with a .net 4.x framework dll. Updating to the project to Core 3.1 fixed the issue.
我正在开发 Core 3 应用程序,并在添加控制器时弹出此问题。我发现 Microsoft.VisualStudio.Web.CodeGeneration.Design 包已更新为 .net 4.x 框架 dll。将项目更新到 Core 3.1 修复了该问题。
回答by Farzad Sepehr
C:\Users\{WindowsUser}\AppData\Local\Microsoft\VisualStudio\16.0_8183e7d1\ComponentModelCache
C:\Users\{WindowsUser}\AppData\Local\Microsoft\VisualStudio\16.0_8183e7d1\ComponentModelCache
Remove from this folder for VS 2019 ....
从此文件夹中删除 VS 2019 ....
回答by Sajithd
A simple VS restart worked for me. I just closed VS and restarted.
一个简单的 VS 重启对我有用。我刚刚关闭了VS并重新启动。


