2013-05-16 31 views
1

當我嘗試使用腳手架模板從控制器方法添加視圖時出現錯誤。選擇哪個模板並不重要,我得到一個錯誤。我使用VS2012更新2MVC 4從控制器添加腳手架視圖拋出錯誤

控制器方法和模型有:

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; } 
    } 

我沒有線索什麼是錯的事。是的,我引用了錯誤消息中提到的程序集。這些程序集是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): error: The host threw an exception while trying to resolve the assembly reference System.ComponentModel.DataAnnotations. The transformation will not be run. The following Exception was thrown: System.NullReferenceException: Object reference not set to an instance of an object. 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, Evidence assemblySecurity, RuntimeAssembly locationHint. StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forintrospection. Boolean suppressSecurityChecks) at System,Reflection.RuntimeAssemblyjnternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forlntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssemblyinternalLoad(String assemblyString. Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivf-lostBinder, Boolean forintrospection) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString. Evidence 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 host, TemplateProcessingSession session)

更新:我不能在這裏發表圖片,所以鏈接下面的屬性。更改副本本地不會改變行爲。

DataAnnotations properties

+0

我已經看到多個網站的評論Code Digger 0.95是這裏的罪魁禍首。如果sophokless提供的答案解決了這個問題,請接受它。 –

回答

7

我有完全相同的問題,它涉及到Microsoft代碼挖掘擴展0.95。禁用擴展允許腳手架過程順利地工作,沒有任何錯誤。

+0

This did ii,thanks – user1268114

+0

sheeeet stupid microsoft:\ –

0

我會運行它實際上看是怎麼回事,加上我不能告訴如果你列出你的組件或錯誤代碼。但這是我認爲可能是錯誤的。歡迎您嘗試一下,看看。

public class InveentoryController : Controller 
    { 
     InventoryRepository repo = new InventoryRepository(); 

     public ActionResult EditInventoryItem(int id = 0) 
     {   
      Inventory inventoryItem = repo.inventoryItem.Find(id); 
       if (inventoryItem == null) 
      { 
       return HttpNotFound(); 
      } 
      return View(inventoryItem); 
     } 
    } 
+0

上面的錯誤消息來自添加視圖中點擊添加按鈕後的模式窗口。當我今天早上嘗試時,我得到了一個不同的錯誤:「c:\ temp \ 3fyklisp.0.cs(5,33):錯誤CS0234:編譯轉換:類型或命名空間'DataAnnotations'不存在於命名空間' System.ComponentModel'(你是否缺少程序集引用)?「 'System.Data'中的'Linq'重複出現此錯誤。 – user1268114

+0

轉到引用,並右鍵單擊System.ComponentModel.DataAnnotations。轉到屬性並截圖並編輯您的問題。複製本地應設置爲False,但有時將其更改爲true有助於。它在System.Web上遇到CS0234錯誤時爲我做了。 – LOTUSMS

相關問題