构建我的 C# 应用程序时缺少程序集
这是我正在 C# 中使用 VS2010 开发的控制台应用程序。我从一位同事那里得到了一个我需要使用的 dll。我添加了 dll 作为引用,添加了所需的名称空间。添加了代码来创建对象的实例并使用了类中的方法。当我完成代码时,VS 没有报告任何错误。编译时,出现错误,指出“找不到类型或命名空间名称 myname”。
收到错误后,我删除了 dll。我删除了名称空间。现在我的代码在我第一次引用该类的地方有红色下划线。我将鼠标悬停在它上面,并使用智能感知添加了名称空间。我使用对象资源管理器来确保它存在。现在我重建解决方案,但遇到了同样的错误。我去了对象资源管理器,dll 引用消失了。但当我查看参考资料时,我发现 dll 仍然存在。我双击将其带到对象资源管理器,但对象定义不存在。这真的很奇怪。这种情况只发生在我得到的这个 dll 上。
我在这里做错了什么?
*** 发现问题了。我朋友的 DLL 似乎是在框架 3.5 上构建的,具有一些依赖项。我将框架更改为 3.5,现在它可以正常构建了。 谢谢,
This is a console application that I am developing using VS2010 in C#. II got a dll from one of my colleague that I need to use. I added the dll as the reference , added the required name space. Added code to create an instance of the object and used a method from the class. When I finished the code there are no errors reported by VS. When I compiled, I got an error stating 'The Type or namespace name myname could not be found'.
After I got the error, I removed the dll. I removed the name space. Now my code has red underline over where I first reference the class. I hover over it and using intellisense I added the namespace. I used object explorer to make sure it is there. Now I rebuild the solution and I got the same error. I went to object explorer and the dll reference is gone. But when I look at the reference I see the dll still there. I double click to take it to object explorer and the object definition is not there. It is really weird. This is happening only to this dll I got.
What am I doing wrong here?
*** Found the problem. It seems the DLL my friend was build on framework 3.5 with some dependencies. I changed the frame work to 3.5 and now it build properly.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每当我遇到这个问题时,几乎总是因为我瞄准了错误的框架。
Whenever I get this problem, it is almost always because I am targeting the wrong framework.
添加引用时,您可能需要确保属性中的 CopyLocal 设置为 True。
When you add the reference, you may want to make sure that CopyLocal is set to True in the properties.