MVC 4从控制器添加脚手架视图会引发错误

use*_*114 1 asp.net-mvc-4

当我尝试使用脚手架模板从控制器方法添加视图时出错.我选择哪个模板并不重要,我收到错误.我正在使用VS2012 Update 2.

控制器方法和模型是:

  public ActionResult EditInventoryItem(int id)
  {
     InventoryRepository repo = new InventoryRepository();
     Inventory inventoryItem = repo.GetSingle(id);
     return View(inventoryItem);
  }

    public class Inventory
   {
      public int Id { get; set; }
      public string Number { get; set; }
      public string Description { get; set; }
      public string Category { get; set; }
      public string Group { get; set; }
      public string Manufacturer { get; set; }
      public string ManufacturerModelNumber { get; set; }
   }
Run Code Online (Sandbox Code Playgroud)

我不知道有什么不对.是的,我引用了错误消息中提到的程序集.程序集是System.ComponentModel.DataAnnotations,System.core,System.Data.Entity和System.Data.Linq.我只放置四条消息中的一条 - 太长了.

C:\ Program Files(x86)\ Microsoft Visual Studio 11.O\Common7JDE\IteniTemplates\CSharp\Web\MVC 4\CodeTemplates\AddView\CSHTML\Details.tt(-1,-1):错误:主持人扔了一个尝试解析程序集引用System.ComponentModel.DataAnnotations时出现异常.转换不会运行.抛出以下异常:System.NullReferenceException:未将对象引用设置为对象的实例.at System.Reflection.RuntimeAssembiy._nLoad(AssembtyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forintrospection,Boolean suppressSecurityChecks)at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName,String codeBase) ,证据assemblySecurity,RuntimeAssembly locationHint.StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forintrospection.布尔suppressSecurityChecks)在系统,Reflection.RuntimeAssemblyjnternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forlntrospection, System.Reflection.RuntimeAssemblyinternalLoad(String assemblyString.Svidence assemblySecurity,StackCrawlMark&stackMark,IntPtr pPrivf-lostBinder,Boolean fo)中的布尔值suppressSecurityChecks)rintrospection)在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString.证据assemblySecurity,StackCrawlMark&stackMark,Boolean forintrospection)at System.Reflection.Assembly.t.oad(String assemblyString)at Microsoft.VisualStudio.Web.Mvc.Userlnterface.MvcTextTemplateHost.ResolveAssemb)yReference(String assemblyReference)at Microsoft.VisualStudio.TextTemplating. Engine.ResolveAssemblyReferences(ITextTemplatingEngineHost主机,TemplateProcessingSession会话)

更新:我无法在此处发布图片,因此请链接到以下属性.更改复制本地不会改变行为.

DataAnnotations属性

小智 7

我有完全相同的问题,它与Microsoft Code Digger扩展0.95有关.禁用扩展允许脚手架进程成功运行而不会出现任何错误.