当我想从另一个项目使用我的类库时,找不到它

发布于 2024-12-14 03:14:47 字数 145 浏览 3 评论 0原文

我有一个类库,我想将其用作其他项目的参考。但是,当我尝试创建此库中的公共类的实例时,我无法构建该项目。它表示找不到类型或命名空间 ClassLibName。 (您是否缺少 using 指令或程序集引用?)。我检查了参考并再次添加。我也添加了命名空间。您对这个问题有什么建议吗?

I have a class library and I want to use it as a reference from another projects. But, when I try to create an instance of a public class wich in this library, I can't build the project. It says, type or namespace ClassLibName could not be found. (are you missing a using directive or an assembly reference?). I checked reference and add it again. I add namespace too. Do you have any suggestion about this problem?

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

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

发布评论

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

评论(5

北城半夏 2024-12-21 03:14:47

确保您尝试创建的类的实例在类库中声明为 public

namespace ClassLibName 
{
    public class SomeClass
    {
        ...
    }
}

然后在客户端项目中添加程序集作为引用,然后

using ClassLibName;

...

SomeClass instance = new SomeClass();

Make sure that instance of the class you are trying to create is declared as public in the class library:

namespace ClassLibName 
{
    public class SomeClass
    {
        ...
    }
}

and then inside the client project you add the assembly as reference and then

using ClassLibName;

...

SomeClass instance = new SomeClass();
与风相奔跑 2024-12-21 03:14:47

我的类库和其他项目有不同的目标框架。我将它们设置为.Net Framework4,问题解决了。感谢您的帮助。

My class library and other project had different target framework. I set them to .Net Framework4, the problem is solved. Thank you for your helps.

画▽骨i 2024-12-21 03:14:47

也许您的库是使用比您的项目更高版本的框架构建的...

如果是这样,您将必须升级您的项目才能构建它(如果可能)...或者降级库!

Maybe your Library is built with a greater version of the framework than your project...

If so, you'll have to upgrade your project to build it if possible... or downgrade the library!

说不完的你爱 2024-12-21 03:14:47

您尝试实例化的类是internal吗?这是默认设置:

// These are equivalent (for a top-level class)
class Foo
internal class Foo

// This is what you need
public class Foo

如果删除实例化类的代码,但保留命名空间的 using 指令和程序集的引用,它是否可以编译?如果是这样,那就表明这确实是特定类的问题,而不是您引用库的方式的问题。

Is the class you're trying to instantiate internal by any chance? That's the default:

// These are equivalent (for a top-level class)
class Foo
internal class Foo

// This is what you need
public class Foo

If you get rid of the code instantiating the class, but do keep the using directive for the namespace and the reference to the assembly, does it compile? If so, that would suggest it really is a problem with the specific class rather than how you're referring to the library.

风和你 2024-12-21 03:14:47

您缺少 using 指令,或者您没有在项目中添加对程序集的引用,或者两者兼而有之。

在解决方案资源管理器中,右键单击“引用”,单击“添加引用”,转到“浏览”,选择其他项目的已编译 dll。

例如,如果您的类位于命名空间 Hello.World 中,您还应该

using Hello.World;

在文件的开头添加。

You are missing an using directive or you didn't add a reference to the assembly in your project, or both.

In solution explorer, right click on References, click Add references, go to Browse, select the compiled dll of the other project.

If, for example, your class is in namespace Hello.World, you should also add

using Hello.World;

at the beginning of the file.

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