C# 编译器说函数未定义,但实际上是

发布于 2024-09-13 01:49:56 字数 915 浏览 4 评论 0原文

我只需要另一双眼睛...我不认为以下内容有任何问题。事实上,我发誓不久前我就有了这样的东西,而且它很有效。

在我的 Collections.dll 中:

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

在另一个 DLL 中,我引用了集合 DLL 项目,并在此函数中使用它:

namespace Organization
{
    public class CBaseEntity : CSuperAutoPool
    {
        protected static CBaseEntity Create()
        {
            //...
            CBaseEntity created = (CBaseEntity)CSuperAutoPool.ActivateByType(callingType); //Error here.
            //...
        }
    }
}

错误:'Collections.CSuperAutoPool' 不包含 'ActivateByType' 的定义

我在 CSuperAutoPool 中使用了 ActivateByType,一种不同的功能,并且该功能没有错误。 Collections DLL 编译时没有错误。在 Organization 命名空间存在的同一 DLL 中,以其他方式使用了 CSuperAutoPool 类的各个其他方面,没有编译器错误。

I just need another pair of eyes... I don't see anything wrong with the following. In fact, I swear I had something just like this not long ago, and it worked.

In my Collections.dll:

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

In another DLL, I have referenced the collections DLL project, and use it in this function:

namespace Organization
{
    public class CBaseEntity : CSuperAutoPool
    {
        protected static CBaseEntity Create()
        {
            //...
            CBaseEntity created = (CBaseEntity)CSuperAutoPool.ActivateByType(callingType); //Error here.
            //...
        }
    }
}

Error: 'Collections.CSuperAutoPool' does not contain a definition for 'ActivateByType'

I have used ActivateByType, within CSuperAutoPool, in a different function, and that one does not have errors. The Collections DLL compiles without errors. In the same DLL where the Organization namespace exists, have used various other aspects of the CSuperAutoPool class in other ways, without compiler errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三岁铭 2024-09-20 01:49:56

您的示例中一定缺少某些内容,或者您​​没有使用您认为正在使用的代码版本,例如,您的项目中可能存在另一个名为 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;
        }
    }
}

There must be something missing from your example, or you are not using the version of the code that you think you are using, e.g. could it be that there is another class called CSuperAutoPool in your project, possibly in a referenced assembly?

The following snippets compiles without errors:

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;
        }
    }
}
木有鱼丸 2024-09-20 01:49:56

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

当我将集合引用添加到组织项目时,它没有选中要在配置管理器中编译的集合项目。换句话说,除非我手动编译,否则我的 Collections DLL 无法编译。

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

Found it! 0xA3 gave me the hint I needed with: "you are not using the version of the code that you think you are using"

When I added the Collections reference to the Organization project, it did not checkmark the Collections project to compile in the Configurations Manager. In other words, my Collections DLL was not compiling unless I did it by hand.

Thank you, that's what I meant by an extra set of eyes. :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文