C# Frequently Asked Questions
来源:互联网 发布:java 混淆加密 编辑:程序博客网 时间:2024/05/24 06:36
Why did I receive the error: "The type ornamespace '<namespace name>' does not exist in the class ornamespace '<parent namespace>' (are you missing an assemblyreference?)"
You need to add a reference in your project to an assembly where that namespace is defined.
If you are using VS.NET:
1. Right click on the References folder on your project.
2. Select Add Reference.
3. Select the .NET tab (or select the Browse button if it is not a .NET Framework assembly).
4. Double-click the assembly containing the namespace in the error message.
5. Press the OK button.
If you are using the command line, use the /r: or /reference: option. For Example:
csc.exe /reference:System.Drawing.dll MyFontDisplayApp.cs
When you recompile, this error will no longer appear.
You can find the assembly, where a namespace is defined, in thedocumentation. Identify one of the types in the namespace that youwant to use. Every type in the .NET Framework has an "About" page thatprovides an overview, basic information about the type, and examplecode if you're lucky. At the bottom of the Overview, for all types,there is a "Requirements" section. This has a Namespace member thattells what namespace the type belongs to. It also tells what assemblytype belongs to, which is the assembly you need to reference in yourapplication. For example, if I had an application that was using Fonttypes, I would look up Font in the .NET Framework documentation, usingthe Index tab, and observe that the Font type is in the System.Drawingnamespace and its assembly is System.Drawing.dll.
Another question related to this is "If I've already declared a using statement, why do I have to add the reference to the project?"
The reason derives from the fact that the using statementand assembly references have two different purposes. Recall that thepurpose of namespaces is to disambiguate type references and providelogical organization of types. When specifying a namespace in a usingstatement, you are telling C# that you want to use the types in thatnamespace in an unqualified manner. The key point is that namespacesare "logical" entities that could exist in one or more assemblies. Onthe other hand, assemblies are "physical" entities that containmultiple types. Assemblies are many things, but for the purposes ofthis discussion, an assembly is the unit of deployment in .NET. So,the reason you need a reference to the assembly that the type islocated in is so that C# can find the physical location of that type,which is not possible with the logical namespace provided by a usingstatement.
[Author: Joe Mayo]
Filed under: C# Language and Compiler, IDE
- C# Frequently Asked Questions
- WinCE Frequently Asked Questions
- SOA Frequently Asked Questions
- Frequently Asked Questions
- Frequently Asked Questions(MPICH2)
- Binder Frequently Asked Questions
- USB Frequently Asked Questions
- Frequently Asked Questions (bouncycastle)
- Frequently Asked Questions
- perf_events Frequently Asked Questions
- OSPF: Frequently Asked Questions
- ovs:Frequently Asked Questions
- perf_events Frequently Asked Questions
- Bank Setup Frequently Asked Questions
- Frequently Asked Questions About Java
- BSP TREE FREQUENTLY ASKED QUESTIONS
- Dependency Walker Frequently Asked Questions
- Unix Programming Frequently Asked Questions
- 安装SqlServer2000以及SP4补丁时的注意事项
- SVN功能小结
- 关于项目博客的要求
- 最近公共祖先(LCA)和RMQ问题
- Linux下SVN安装配置全程实录
- C# Frequently Asked Questions
- 理解和认识udev
- yield迭代器
- Postfix email foward 配置指南
- 唐骏的秘密:我从最后一名开始努力
- DOM操作table
- c#.net常用函数列表
- 转载任正非的我的父亲母亲
- erlangR13B对unicode的支持