为什么我不能在MVC应用程序中使用VS2010的“添加视图”功能呢?

时间:2022-04-16 07:27:08

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

Genesis_0_02 -具有实际的MVC控制器、视图等。这是一个启动项目

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.

我正在修改存储库和mvc项目。我可以添加一些视图,但随后自动视图生成(右击+“添加视图”)停止工作。

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.

后面是一个stacktrace,我无法复制粘贴。

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.)

我可以使用Genesis_0_02命名空间中的模型/类创建视图。但不是从《创世纪》。域命名空间。(尽管《创世纪》。域类确实显示在列表中)

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.

顺便说一下,我可以手动创建新的视图,它们可以工作。

3 个解决方案

#1


0  

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

这种行为很奇怪。我曾见过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.

1)创建一个新的MVC web项目,并添加对- Genesis.Domain的引用。看看从控制器添加视图是否有效。

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

如果是,请在web中验证以下配置。配置文件(在视图文件夹下)在您的工作项目中—特别是

PageParserFiltertype

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.

如果没有,请尝试在dev机器上重新安装框架和VS2010 MVC 2 / 3。

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

您还可以使用下面的链接http://bradwilson.typepad.com/blog/2010/03/diagnostics -aspnet-mvc-problems.html

Good Luck!

好运!

#2


1  

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:

我也有同样的问题。一位同事通过调试模板过程解决了这个问题。他发现VS2010一直在本地文件夹中查找dll,在我们的例子中是:

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

“C:\程序文件(x86)\微软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.

在这个位置创建文件夹之后,我们将Dll和它的依赖项放在这个文件夹中,错误就消失了。

It think this is a definite bug in VS2010.

它认为这是VS2010中一个明确的错误。

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

我们必须在上面的路径中添加与引用的Dll名称匹配的文件夹。

#3


0  

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.

我自己从来没有遇到过这个问题,但从这些错误消息中,我只想到这个问题。

#1


0  

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

这种行为很奇怪。我曾见过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.

1)创建一个新的MVC web项目,并添加对- Genesis.Domain的引用。看看从控制器添加视图是否有效。

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

如果是,请在web中验证以下配置。配置文件(在视图文件夹下)在您的工作项目中—特别是

PageParserFiltertype

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.

如果没有,请尝试在dev机器上重新安装框架和VS2010 MVC 2 / 3。

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

您还可以使用下面的链接http://bradwilson.typepad.com/blog/2010/03/diagnostics -aspnet-mvc-problems.html

Good Luck!

好运!

#2


1  

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:

我也有同样的问题。一位同事通过调试模板过程解决了这个问题。他发现VS2010一直在本地文件夹中查找dll,在我们的例子中是:

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

“C:\程序文件(x86)\微软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.

在这个位置创建文件夹之后,我们将Dll和它的依赖项放在这个文件夹中,错误就消失了。

It think this is a definite bug in VS2010.

它认为这是VS2010中一个明确的错误。

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

我们必须在上面的路径中添加与引用的Dll名称匹配的文件夹。

#3


0  

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.

我自己从来没有遇到过这个问题,但从这些错误消息中,我只想到这个问题。