C# FAQ: Am I missing an assembly reference


Jump to: navigation, search

Am I missing an assembly reference?

Most developers encounter the following error frequently:


 Error (program output)
The type or namespace '<namespace name>' does not exist in

the class or namespace '<parent namespace>' (are you missing an assembly reference?)

This error message indicates that a reference must be added in the project to an assembly where that namespace is defined.

Adding a reference using Visual Studio .NET

When using Visual Studio .NET, follow these steps to add a reference:

  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 not a .NET Framework assembly.
  4. Double click the assembly containing the namespace named in the error message.
  5. Press the OK button.

Adding a reference from the Windows command line

When using the command line, use the /r: or /reference: option. Here is an example:

csc.exe /reference:System.Drawing.dll FontDisplayAppl.cs

Upon recompilation, the error message will have magically disappeared!

To find the assembly in which a namespace is defined, check the documentation. Identify a type in the namespace that must be used. Every type in the .NET Framework has an "About" page which gives a brief overview, some basic type information, and—hopefully—sample source code.

Near the bottom of the "Overview" section, find the "Requirements" section. It contains a Namespace member which specifies the namespace to which the type belongs. Also, this section lists to which assembly a type belongs as well as which assembly the application must reference.

For instance, if an application uses Font types, look up Font in the .NET Framework documentation using the Index tab. Note that the Font type is in the System.Drawing namespace and its assembly is System.Drawing.dll.


More Visual C# and .NET FAQs

Go to Visual CSharp FAQ (main page).

Consider these related Frequently Asked Questions—FAQs:

  1. Am I missing an assembly reference?
  2. Are .NET generics like C++ templates?
  3. Are there free .NET decompilers?
  4. Does .NET run only on Windows?
  5. How call a method using a name string?
  6. How convert a string type to an int type?
  7. How create an instance of a type using only its name?
  8. How display int as a binary number, a string of 0s and 1s?
  9. How enforce coding guidelines for custom .NET assemblies?
  10. How ensure that only one instance of an application will run?
  11. How get assembly attributes at runtime?
  12. How good are .NET decompilers?
  13. How protect .NET code against decompilation?
  14. How protect .NET code from reverse engineering?
  15. How start another program from .NET?
  16. How to read files with accented characters?
  17. Is there a .NET equivalent to regsvr32?
  18. Must the framework be installed to run .NET applications?
  19. Should calling Initialize() on a reference type array fill it with objects?
  20. What about .NET decompilers that allow code to be submitted from browsers?
  21. What compression and zipping capabilities does .NET have?
  22. What do all the .NET acronyms mean?
  23. What does a .NET decompiler do?
  24. What is .NET?
  25. What is the difference between Convert.ToInt32(string) and Int32.Parse(string)?
  26. What is the easiest way to fetch a Web page in .NET?
  27. Why does .NET make arithmetic errors?

Share this page
  • del.icio.us
  • Facebook
  • Google+
  • StumbleUpon