问题描述
这是我遇到过的最奇怪的错误.
This is the weirdest error I have ever encountered.
这个MVC网络项目到目前为止一直运行良好.几周没有任何人对此进行研究.
This MVC web project was working fine until today. It hasn't been worked on by anyone in a couple of weeks.
即使一切都没有改变,但现在简单运行它会导致:
Even though NOTHING has changed, simply running it now results in:
(x5)
(x1)
在项目中有对CMSModels的引用.删除此引用后,命名空间中的每个其他类给我带来了大约200个额外的错误,因此我知道它是可行的,但对于这两个错误却无效.
There is a reference to CMSModels in the project. Removing this reference gives me about 200 extra errors for each other class in the namespace, so I know it is working, but not for these two errors.
这是错误所指向的生成代码行:
This is the line of generated code which the error points to:
public class views_colorbox_index_aspx : System.Web.Mvc.ViewPage<IEnumerable<CMSModels.Colourbox>>, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
...
public class views_colorbox_content_ascx : System.Web.Mvc.ViewUserControl<CMSModels.ViewModels.ColourboxViewModel> {
Intellisense正在获取CMSModels.ColourBox和CMSModels.ViewModels.ColourboxViewModel的位置.
Intellisense is picking up the location of both CMSModels.ColourBox and CMSModels.ViewModels.ColourboxViewModel.
我完全陷入了困境.非常感谢,因为我完全不知所措.
I am completely stumped. Any help greatly appreciated as I am completely at a loss.
好的,我找到了问题-但没有解决的办法.
OK I have found the issue - but not the solution.
该类定义为
public class ColourBoxViewModel
但是,生成的代码正在寻找"ColourboxViewModel"类.注意小写的B.自动生成代码从何处获取类的名称?在项目中搜索时,用小写b表示没有提及它.
yet the generated code is looking for a class of 'ColourboxViewModel'. Note the lowercase B. Where does the auto-gen code get the names of classes from? Search in project reveals no mentions of it with a lowercase b.
对于ColourBox类来说,问题是相同的.
The issue is the same for the ColourBox class.
问题已解决-@FrantišekŽiačik,您是正确的.有一个文件夹被排除在项目之外(这就是为什么在整个项目中以及在Visual Studio中的视图中搜索都找不到任何文件夹的原因),其中包含错误键入的herit语句.最初由外包商创建时,排除的文件夹称为ColorBox.团队中的另一个开发人员将其复制并重命名为ColourBox,我决定引用正确拼写所有内容".该开发人员现在仅允许使用口语拼写法进行编码.
Problem solved - and @František Žiačik you were correct. There was a folder which had been excluded from the project (which is why searching in entire project and within the views in visual studio found nothing) which contained the incorrectly typed inherit statement. The excluded folder was called ColorBox when originally created by outsourcers. This had been copied and renamed as ColourBox by another dev on the team who decided to, and I quote, 'spell everything correctly'. Said dev is now only allowed to code using a Speak n' Spell.
推荐答案
所以这是我的猜测.
在您的content.ascx
视图(或任何命名的视图)中,您已经声明:
In your content.ascx
view (or whatever it's named) you have declared:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CMSModels.ViewModels.ColourboxViewModel>" %>
代替
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CMSModels.ViewModels.ColourBoxViewModel>" %>
这篇关于类型或名称空间名称"X"在名称空间"Y"中不存在-在VS生成的代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!