Visual Studio 构建错误:声明其他程序集中的类成员不存在
我有一个网站解决方案,其中包含一个具有域类的项目。
我已将公共自动属性(get;set;)添加到域类之一。网站上的页面引用了此属性 - 它是使用 IntelliSense 添加到页面的。
网站项目构建正常。但是当我构建解决方案时,我收到旧的“类不包含属性的定义”错误。但是,如果我右键单击 aspx.cs 文件中的属性,则会直接转到域类中的声明。
解决方案中的其他网站项目可以调用该类的此属性,不会出现错误。
实际使用该网站时会出现同样的异常。
Visual Studio 似乎遇到了一些奇怪的事情。
有什么建议可能会出什么问题吗?
谢谢
大卫
编辑:以下是一系列步骤中的一些进一步观察。
- 清理解决方案(表示 14 个成功;解决方案中有 16 个项目)
- 构建解决方案(表示 16 个成功)
- 重建解决方案(如所述失败)
- 构建解决方案(如所述失败)
该网站在任何时候都无法真正工作 - 它总是给出错误。
它似乎预编译成功。
编辑2: 我已删除项目引用并重新添加它,但问题仍然存在。
编辑3: 我已在解决方案中添加了一个新的 webiste 项目,并将所有文件从现有网站复制到新网站。新网站和现有网站都存在该问题。
I have a website solution which contains a project with domain classes.
I have added a public auto property (get; set;) to one of the domain classes. A page on the website references this property - it was added to the page using IntelliSense.
The website project builds okay. But when I build the solution, I get the old 'Class does not contain a definition for Property' error. However, if I right click on the property in the aspx.cs file, it takes me right to the declaration in the domain class.
The other website project in the solution can call this property of the class without errors.
Actually using the website fails with the same exception.
Seems like Visual Studio is having some kind of weird episode here.
Any suggestions what might be going wrong?
Thanks
David
Edit: Here are some further observations in a series of steps.
- Clean Solution (says 14 succeeded; there are 16 projects in the solution)
- Build Solution (says 16 succeeded)
- Rebuild Solution (fails as described)
- Build Solution (fails as described)
At no point does the website actually work - it always gives the error.
It does appear to precompile successfully.
Edit 2:
I have removed the project reference and re-added it, but the problem remains.
Edit 3:
I have added a new webiste project to the solution and copied all the files across from the existing website to the new website. The problem exists in the new website as well as the existing one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试使用 System.IO.FileSystemWatcher 或 SysInternals 之一尝试查明编译器是否正在访问旧的、缓存的程序集副本的工具。
You might try using System.IO.FileSystemWatcher or one of the SysInternals tools to try to find out if the compiler is accessing an old, cached copy of your assembly somewhere.
也许重置 IIS 或应用程序池会有所帮助?
另外,如果程序集已在 GAC 中注册,则删除它并重新安装可能会有所帮助。
Perhaps a reset of IIS or the Application Pools helps a bit?
Also, if the assembly is registered in the GAC, perhaps removing it and installing it back again might help.
仔细检查难以找到该属性的项目的构建顺序和/或依赖关系。该项目应该要求首先构建其他项目。
Double check the Build Order and/or Dependencies on the project that is having difficulty finding the property. That project should require that the other project(s) build first.
好的,问题是我正在使用的类(据报道不包含特定属性)称为 Case。尽管 C# 假定区分大小写,但可能它与保留字“case”发生了冲突,这导致了编译过程中的问题。
完全限定类名解决了问题,但我想我可能只是将类重命名为“ProbateCase”。
不得不说,这明显是Visual Studio编译过程中的一个bug。不仅“Case”不应该等于 C# 中的“case”,而且该类在我的解决方案中已经存在了大约一年半的时间,而且以前从未出现过这个问题。其他项目可以自由使用该类,而无需限定其名称。
发牢骚过去。生活仍在继续。
Okay, the problem was that the class I was using (which reportedly didn't contain the particular property) is called Case. Despite C#'s supposed case sensitivity, presumably it somehow clashed with the reserved word 'case', and this caused the problem during compilation.
Fully qualifying the class name fixed the problem, but I think I might just rename the class 'ProbateCase'.
I have to say this is clearly a bug in Visual Studio's compilation process. Not only should 'Case' not equal 'case' in c#, but also the class has existed in my solution for about a year and a half and this problem has never arisen before. Other projects can freely use the class without qualifying its name.
Grumble over. Life goes on.