Error generating MVC view for Entity Framework model
Entity Framework, Error, Mvc April 4th, 2009
I’m trying to generate a view for Asp.Net MVC 1.0 using an Entity Framework model. This is from Details.tt. Anyone seen this error?
I get this the first time I try to generate:
error CS0234: Compiling transformation: The type or namespace name ‘Data’ does not exist in the namespace ‘System’ (are you missing an assembly reference?)
And if I try to generate again:
—————————
Template Processing resulted in 2 Errors
—————————
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC\CodeTemplates\AddView\Details.tt(-1,-1) : error : The host threw an exception while trying to resolve the assembly reference ‘System.Data.Entity’. The transformation will not be run. The following Exception was thrown:
System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.VisualStudio.Web.Mvc.MvcTextTemplateHost.Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost.ResolveAssemblyReference(String assemblyReference)
at Microsoft.VisualStudio.TextTemplating.Engine.CompileAndRunCode(String generatorCode, ITextTemplatingEngineHost host, TemplateProcessingSession session)
About
I just found this post after searching the web for “Template Processing resulted in 2 Errors”, because I had the same error. (See below for more about how I got the error)
On a hunch, I closed Visual Studio 2008, and ran it again, but this time I ran it “as administrator”. Sure enough, now the step worked perfectly.
Why? No idea. But it worked for me.
(I am working through the tutorial located here http://weblogs.asp.net/scottgu/archive/2009/03/10/free-asp-net-mvc-ebook-tutorial.aspx) and am on page 59/60 where you add a new strongly typed “List” view.
Best of luck!
(If it matters, this is on my laptop running Windows 7 Beta x86.)