不能添加MVC控制器VS2012给人"对象引用不设置到对象&QUOT的实例; [英] Cannot add a MVC controller VS2012 gives "object reference not set to an instance of an object"

查看:319
本文介绍了不能添加MVC控制器VS2012给人"对象引用不设置到对象&QUOT的实例;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经广泛搜索并不能找到这个问题在这个星球上另一个人......

其症状是:
在Visual Studio 2012,上从VS2010升级,配置为从VS2012和VS2010双版编辑的MVC 4.0项目。当我在控制器文件夹,右键单击,然后选择添加 - >控制器...从上下文菜单中,我得到一个对象引用不设置到对象的实例错误从Visual Studio。


该项目现有的code运行正常,如果我使用添加 - >新建项目选项,而不是,并选择从对话框中的控制器,那么我可以添加一个空白控制器。我只是不能使用上述方法增加一个类型的控制器。


如果不过我创建一个新的项目MVC4,那么我可以添加再次使用相同的菜单类型化的控制器,所以这个问题不会在Visual Studio的安装存在,它在项目文件存在。
我还检查我的项目和新的MVC项目和所有的新项目引用的参考文献都包含在我的项目。
有没有人遇到过类似的事情?

怎么办解决这一问题?

I have searched extensively and cannot find another person on the planet with this problem...
The symptoms are:
In Visual Studio 2012, on a MVC 4.0 Project that was upgraded from VS2010 and is configured for dual version editing from VS2012 and VS2010. When I right-click on the Controllers Folder and select Add->Controller... from the context menu, I get an "Object reference not set to an instance of an object" error from Visual Studio.

The existing code in the project runs fine, and if I use the Add->New Item option instead, and pick the Controller from the dialog box, then I can add a blank controller. I just cannot add a typed controller using the method above.

If I however create a new MVC4 Project, then I can add typed controllers again using the same menu, so the problem does not exist in Visual Studio's installation, it has to exist in the Project File.
I have also checked the references between my project and a new MVC Project and all the new project references are included in my project.
Has anyone experienced something similar?

How do I fix this?

推荐答案

这个问题似乎已经被MvcScaffolder包的一个不完整的安装/注册引起的。
下面的程序解决了我,我的问题。

The issue seems to have been caused by an incomplete install/registration of the MvcScaffolder package. The following process resolved my issue for me.

启动Visual Studio并打开项目。 打开包管理器控制台即可。 (这是绝招或信息缺失的环节,导致了解决方案...)

Start Visual Studio and open the project. Open the Package Manager Console. (This was the "trick" or missing piece of information that led to the solution...)

在这里,我看到了造成注册时使用的PowerShell脚本以下错误:

Here I saw the following error caused by the PowerShell script used for registration:

New-Object : Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
At <ProjectPath...>\packages\MvcScaffolding.1.0.9\tools\registerWithMvcTooling.ps1:163 char:27
+     $newProvider = New-Object <<<<  $powerShellScaffolderProviderType($mvcScaffoldingProvider)
    + CategoryInfo          : NotSpecified: (:) [New-Object], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException, Microsoft.PowerShell.Commands.NewObjectCommand

当我检查了注册架子工从Package Manager控制台我:

When I checked the registered scaffolders from the Package Manager Console I got:

PM> get-defaultscaffolder

DefaultName          ScaffolderName
Action               MvcScaffolding.Action
Controller           MvcScaffolding.Controller
CustomScaffolder     T4Scaffolding.CustomScaffolder
CustomTemplate       T4Scaffolding.CustomTemplate
DbContext            T4Scaffolding.EFDbContext
Mailer               Mailer.Razor
Repository           T4Scaffolding.EFRepository
UnitTest             MvcScaffolding.ActionUnitTest
View                 MvcScaffolding.RazorView
Views                MvcScaffolding.Views 

所以很明显的脚手架被配置为使用MvcScaffolding包,但包了注册错误。

So clearly the scaffolders are configured to use the MvcScaffolding package, but the package had a registration error.

有关该错误的快速搜索提供的这个链接<一个href=\"http://mvcscaffolding.$c$cplex.com/discussions/437692\">http://mvcscaffolding.$c$cplex.com/discussions/437692它指的是<一href=\"https://visioautomation.$c$cplex.com/discussions/397034\">https://visioautomation.$c$cplex.com/discussions/397034这意味着从<一个安装PowerShell的3,这实际上是Windows管理框架3.0的一部分,可href=\"http://www.microsoft.com/en-us/download/details.aspx?id=34595\">http://www.microsoft.com/en-us/download/details.aspx?id=34595.提示因为我跑赢的时候我选择了Windows6.1-KB2506143-x64.msu程序文件7-64位。

A quick search for the error provided this link http://mvcscaffolding.codeplex.com/discussions/437692 which refers to https://visioautomation.codeplex.com/discussions/397034 that suggests installing PowerShell 3, which is actually part of the Windows Management Framework 3.0, available from http://www.microsoft.com/en-us/download/details.aspx?id=34595. I picked the Windows6.1-KB2506143-x64.msu file when prompted because I’m running Win 7-64-bit.

安装后重新启动电脑,重新打开Visual Studio和项目,并期待在包管理器控制台。如果错误消失了,那就这样是控制器的问题。

Restart the PC after installation, re-open Visual Studio and the project and look at the Package Manager Console. If the error is gone, then so is the controller problem.

这篇关于不能添加MVC控制器VS2012给人&QUOT;对象引用不设置到对象&QUOT的实例;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆