yeomandev
yeomandev

Reputation: 11796

Why can't I use VS2010's "Add View" Feature in my MVC application?

This is weird,

I have a solution with two projects in it...

Genesis.Domain - Is a Class Library and has the repository in it.

Genesis_0_02 - Has the actual MVC Controllers, views, etc... and it's the startup project

I am in the process of modifying the repository and the mvc project. I was able to add a couple of views, but then the automatic view generation (right click + "Add View") stopped working.

An error dialogue box popped up with an error and a stack trace. I can't copy-paste it but basically it said:

C:\pathto\CodeTemplates\AddView\Empty.tt(-1,-1): error : An exception was thrown 
while running the transformation code. The process cannot continue. The following
exception was thrown:
System.IO.FileNotFoundException: Could not load file or assembly 'Genesis.Domain,
Version=1.0.0.0, Culture Neutral, etc.etc.' or one of its dependencies. The system
cannot find the file specified.
File name: 'Genesis.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

Followed by a stacktrace that I'm unable to copy paste.

What could cause this? Genesis.Domain is referenced and has been referenced through all of development. The project/solution compiles fine and it runs fine.

I am able to make views using models/classes from Genesis_0_02 namespace. But not from Genesis.Domain namespace. (Even though Genesis.Domain classes do show in the list.)

Also, unusual classes have popped up in the "Add View" class list. they look like this:

Genesis_0_02.Controllers.AdminMemberController+<>c__DisplayClass8+<>c__DisplayClasse>

I have no idea where those are coming from.

What could be causing this? How do i get the "Add View" feature working again?

Edit

BTW: I can manually create new views and they do work.

Upvotes: 2

Views: 1949

Answers (3)

skobama
skobama

Reputation: 11

I had this same problem. A colleague at work solved the issue by debugging the template process. He found that VS2010 was ALWAYS looking for the dll's in a local folder, in our case it was:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\"

Once we created the folder in this location, we placed the Dll and it's dependencies in this folder and the error went away.

It think this is a definite bug in VS2010.

We had to add folder in the above path that matched the name of the referenced Dll.

Upvotes: 1

swapneel
swapneel

Reputation: 3061

This behaviour is very weird. I have seen weirdnes for VS2008.

Try Couple of things as below

1] Create a New MVC web project and add reference to - Genesis.Domain. and See if Add View from controller works on it.

If yes then verify below configuration in web.config file (which is Under Views folder) in your working project - specifically

PageParserFiltertype

<pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>

If No Then try to reinstall Framework and VS2010 MVC 2 / 3 on dev machine.

also you could use below link http://bradwilson.typepad.com/blog/2010/03/diagnosing-aspnet-mvc-problems.html

Good Luck!

Upvotes: 0

David Ipsen
David Ipsen

Reputation: 1533

It sounds like the reference to your class library project was somehow messed up. Have you tried removing the class library project from your solution and then re-adding the project to the solution?

I've never run into this problem myself, but it's the only thing that comes to mind from those error messages.

Upvotes: 0

Related Questions