當我嘗試使用腳手架模板從控制器方法添加視圖時出現錯誤。選擇哪個模板並不重要,我得到一個錯誤。我使用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)
更新:我不能在這裏發表圖片,所以鏈接下面的屬性。更改副本本地不會改變行爲。
我已經看到多個網站的評論Code Digger 0.95是這裏的罪魁禍首。如果sophokless提供的答案解決了這個問題,請接受它。 –