C#编译器说函数没有定义,当它被定义时

C#编译器说函数没有定义,当它被定义时,c#,dll,function,reference,definition,C#,Dll,Function,Reference,Definition,我只需要另一双眼睛。。。我看不出下面有什么问题。事实上,我发誓不久前我就有过这样的经历,而且很有效 在my Collections.dll中: namespace Collections { public class CSuperAutoPool { public static CSuperAutoPool ActivateByType(Type typeToBeActivated, params object[] activatedArguments) {

我只需要另一双眼睛。。。我看不出下面有什么问题。事实上,我发誓不久前我就有过这样的经历,而且很有效

在my Collections.dll中:

namespace Collections
{
   public class CSuperAutoPool
   {
      public static CSuperAutoPool ActivateByType(Type typeToBeActivated, params object[] activatedArguments)
      {
          //...
      }
   }
}
在另一个DLL中,我引用了collections DLL项目,并在此函数中使用它:

namespace Organization
{
    public class CBaseEntity : CSuperAutoPool
    {
        protected static CBaseEntity Create()
        {
            //...
            CBaseEntity created = (CBaseEntity)CSuperAutoPool.ActivateByType(callingType); //Error here.
            //...
        }
    }
}
错误:“Collections.CSuperAutoPool”不包含“ActivateByType”的定义


我在CSSuperAutoPool中的另一个函数中使用了ActivateByType,并且该函数没有错误。集合DLL编译时没有错误。在组织名称空间存在的同一DLL中,您以其他方式使用了CSuperAutoPool类的各种其他方面,没有编译器错误。

您的示例中一定缺少某些内容,或者您没有使用您认为正在使用的代码版本,例如,在您的项目中,可能在引用的程序集中存在另一个名为
CSuperAutoPool
的类吗

以下代码段编译时没有错误:

namespace Collections
{
    public class CSuperAutoPool
    {
        public static CSuperAutoPool ActivateByType(
            Type typeToBeActivated, params object[] activatedArguments)
        {
            //...
            return null;
        }
    }
}

namespace Organization
{
    using Collections;
    public class CBaseEntity : CSuperAutoPool
    {
        protected static CBaseEntity Create()
        {
            Type callingType = null;
            //...
            CBaseEntity created = 
                (CBaseEntity)CSuperAutoPool.ActivateByType(callingType); 
            //...
            return created;
        }
    }
}

您的示例中一定缺少某些内容,或者您没有使用您认为正在使用的代码版本,例如,您的项目中可能存在另一个名为
CSuperAutoPool
的类,可能在引用的程序集中

以下代码段编译时没有错误:

namespace Collections
{
    public class CSuperAutoPool
    {
        public static CSuperAutoPool ActivateByType(
            Type typeToBeActivated, params object[] activatedArguments)
        {
            //...
            return null;
        }
    }
}

namespace Organization
{
    using Collections;
    public class CBaseEntity : CSuperAutoPool
    {
        protected static CBaseEntity Create()
        {
            Type callingType = null;
            //...
            CBaseEntity created = 
                (CBaseEntity)CSuperAutoPool.ActivateByType(callingType); 
            //...
            return created;
        }
    }
}

找到了!0xA3给出了我需要的提示:“您没有使用您认为正在使用的代码版本”

当我将集合引用添加到组织项目时,它没有选中要在Configuration Manager中编译的集合项目。换句话说,除非我手工编译,否则我的集合DLL不会编译


谢谢,这就是我所说的额外一双眼睛的意思。:-)

找到了!0xA3给出了我需要的提示:“您没有使用您认为正在使用的代码版本”

当我将集合引用添加到组织项目时,它没有选中要在Configuration Manager中编译的集合项目。换句话说,除非我手工编译,否则我的集合DLL不会编译


谢谢,这就是我所说的额外一双眼睛的意思。:-)

看起来您用两个参数声明函数,然后用一个参数调用它。我看到您有
参数作为可选参数,但我不确定-如果您不需要任何其他参数(我不经常使用该功能),是否必须传递
null
。@fructedWithFormsDesigner:否,您不需要传递null。@fructedWithFormsDesigner-当一个参数被标记为
params
时,在调用该方法时省略它是可以的。@0xA3:好吧,那么,我也难倒了!您是否尝试过在Visual Studio中执行“清洁解决方案”,然后重新构建?这有时会整理出任何有趣的行为……看起来像是用两个参数声明函数,然后用一个参数调用它。我看到您有
参数作为可选参数,但我不确定-如果您不需要任何其他参数(我不经常使用该功能),是否必须传递
null
。@fructedWithFormsDesigner:否,您不需要传递null。@fructedWithFormsDesigner-当一个参数被标记为
params
时,在调用该方法时省略它是可以的。@0xA3:好吧,那么,我也难倒了!您是否尝试过在Visual Studio中执行“清洁解决方案”,然后重新构建?这有时可以解决任何有趣的行为。。。