问题描述
我知道错误消息很常见,并且有很多关于此错误的问题,但到目前为止没有任何解决方案对我有帮助,所以我决定提出这个问题.与大多数类似问题的不同之处在于我使用 App_Code 目录.
I know the error message is common and there are plenty of questions on SO about this error, but no solutions have helped me so far, so I decided to ask the question. Difference to most of similar questions is me using App_Code directory.
错误信息:
CS0012: The type 'Project.Rights.OperationsProvider' is defined in an
assembly that is not referenced. You must add a reference to assembly
'Project.Rights, version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
源文件:
c:inetpubwwwrootTestWebsiteApp_CodeCompanyProjectBusinessLogicManager.cs
以下建议 此处和此处,我已经删除了 C:WindowsMicrosoft.NET/*.* 中 Project.Rights.dll 的所有实例根据 this,我检查了有问题的 .cs 文件是否已构建操作设置为编译".他们是这样.我还仔细检查了包含Project.Rights.OperationsProvider"类型的 .cs 文件是否已部署到 App_Code 目录.
Following suggestions here and here, I have deleted all instances of Project.Rights.dll inside C:WindowsMicrosoft.NET/*.*According to this, I checked if .cs files in question have build action set to "Compile". They do.I have also double checked that the .cs file containing the "Project.Rights.OperationsProvider" type is deployed to App_Code directory.
出于某种原因,应用程序没有在 App_Code 目录中查找类型.由于我已经删除了 Project.Rights.dll 的所有实例(我知道),我不知道错误消息提到的是哪个程序集.
For some reason, application is not looking for the type in the App_Code directory. Since I've deleted all instances of Project.Rights.dll (that I know of), I don't know which assembly the error message is mentioning.
推荐答案
当您收到此错误时,并不总是很明显发生了什么,但正如错误所说 - 您缺少参考.以下面这行代码为例:
When you get this error it isn't always obvious what is going on, but as the error says - you are missing a reference. Take the following line of code as an example:
MyObjectType a = new MyObjectType("parameter");
它看起来很简单,您可能正确地引用了MyObjectType".但是让我们说MyObjectType"构造函数的重载之一采用您没有引用的类型.例如,有一个重载定义为:
It looks simple enough and you probably have referenced "MyObjectType" correctly. But lets say one of the overloads for the "MyObjectType" constructor takes a type that you don't have referenced. For example there is an overload defined as:
public MyObjectType(TypeFromOtherAssembly parameter) {
// ... normal constructor code ...
}
这至少是您会收到此错误的一种情况.因此,寻找这种类型的模式,其中您引用了类型,但不是所有类型的属性或方法参数的类型,这些类型在该类型上调用的函数是可能的.
That is at least one case where you will get this error. So, look for this type of pattern where you have referenced the type but not all the types of the properties or method parameters that are possible for functions being called on that type.
希望这至少能让你朝着正确的方向前进!
Hopefully this at least gets you going in the right direction!
这篇关于类型定义在未引用的程序集中,如何查找原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!