Share via


Why did I receive the error: "The type or namespace '' does not exist in the class or namespace '' (are you missing an assembly reference?)"

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 the documentation.  Identify one of the types in the namespace that you want to use.  Every type in the .NET Framework has an "About" page that provides an overview, basic information about the type, and example code if you're lucky.  At the bottom of the Overview, for all types, there is a "Requirements" section.  This has a Namespace member that tells what namespace the type belongs to.  It also tells what assembly type belongs to, which is the assembly you need to reference in your application.  For example, if I had an application that was using Font types, I would look up Font in the .NET Framework documentation, using the Index tab, and observe that the Font type is in the System.Drawing namespace 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 statement and assembly references have two different purposes.  Recall that the purpose of namespaces is to disambiguate type references and provide logical organization of types.  When specifying a namespace in a using statement, you are telling C# that you want to use the types in that namespace in an unqualified manner.  The key point is that namespaces are "logical" entities that could exist in one or more assemblies.  On the other hand, assemblies are "physical" entities that contain multiple types.  Assemblies are many things, but for the purposes of this discussion, an assembly is the unit of deployment in .NET.  So, the reason you need a reference to the assembly that the type is located in is so that C# can find the physical location of that type, which is not possible with the logical namespace provided by a using statement.

[Author: Joe Mayo]

Comments

  • Anonymous
    May 05, 2004
    excellent - short and to the point. thanks

  • Anonymous
    May 09, 2004
    I'm tring to use this method (StrToInt), but when i try, this error apears "The type or namespace does not exist in the class or namespace", what should i do?

  • Anonymous
    May 09, 2004
    I'm tring to use this method (StrToInt), but when i try, this error apears "The type or namespace does not exist in the class or namespace", what should i do?

  • Anonymous
    May 18, 2004
    thanks....helped me.

  • Anonymous
    June 16, 2004
    I'm using assembly references for shared code in a large project (100+ assemblies). We routinely get this same error--despite having references to the specified assembly--when (it seems) different "major" assemblies have been compiled with references to different versions of the same utility assembly. The signatures of the utility assemblies has not changed.

    This is HUGELY frustrating--and has a large development team grumbling.

  • Anonymous
    July 20, 2004
    Thanks so much!!! I searched several places, including VS help, and do you think anybody would tell me to right click on reference??

    Not until I found this site. Thank you !!!!

  • Anonymous
    January 09, 2010
    still i couldn't use methods in the referenced project. I used class library project. Please help me. I got stuck in that.

  • Anonymous
    January 15, 2010
    This error can also appear even when you have an appropriate reference & using statement.  Generally it happens when the compiled version is out of date and the code you're working on has a number of syntax errors (maybe your mid conversion/refactor of a block of code). In this situation you can resolve the error by choosing "Clean Solution" or "Clean <Your Poject Name>" from the Build menu in Visual Studio.

  • Anonymous
    March 28, 2010
    Thanks EricB, you resolved my problem.

  • Anonymous
    April 01, 2010
    You should also check that the "Build Action" of the .cs file is set to 'compile'

  • Anonymous
    June 30, 2010
    Thank you, I have looked for it so much

  • Anonymous
    August 10, 2010
    The comment has been removed

  • Anonymous
    August 23, 2010
    I have a Windows Project called Surveys and a Class Library project called Surveys.Library and I can clearly see the reference to Surveys.Library sitting within Surveys but am still getting this error. I cannot see why this would be. Every time I delete the reference and re-add it, it's fine until I hit f5 and it doesn't pick up the reference even though it's still there.

  • Anonymous
    August 23, 2010
    Okay, answered my own question. A bad using reference in the library seems to break the reference in the Main project but the system never attributes the bad library reference as being the problem.

  • Anonymous
    September 18, 2010
    .net f/w version 2 the error is Error 1 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) C:ashish websiteTEMPLATESBHAGWAN PARSHURAM INSTITUE OF TECHNOLOGY 2010-09-19 0719.54MasterPage.master.cs 3 14 C:...BHAGWAN PARSHURAM INSTITUE OF TECHNOLOGY 2010-09-19 0719.54 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class MasterPage : System.Web.UI.MasterPage {    protected void Page_Load(object sender, EventArgs e)    {    }    protected string RenderMenu()    {        var result = new StringBuilder();        RenderMenuItem("Home", "Default.aspx", result);        RenderMenuItem("About", "About.aspx", result);        return result.ToString();    }    void RenderMenuItem(string title, string address, StringBuilder output)    {        output.AppendFormat("<li><a href="{0}" ", address);        var requestUrl = HttpContext.Current.Request.Url;                if (requestUrl.Segments[requestUrl.Segments.Length - 1].Equals(address, StringComparison.OrdinalIgnoreCase)) // If the requested address is this menu item.            output.Append("class="ActiveMenuButton"");        else            output.Append("class="MenuButton"");        output.AppendFormat("><span>{0}</span></a></li>|", title);    } } wat to do plz me fellas

  • Anonymous
    October 19, 2010
    Visual Studio still has issues with my code even after I've added the assembly reference.

  • Anonymous
    October 20, 2010
    Its really helpful

  • Anonymous
    December 01, 2010
    Visual Studio is displaying the same error although I modified the reference of the assembly and the using directive for DataSetTableAdapter.

  • Anonymous
    March 15, 2011
    Visual Studio still has issues with this.  I add the reference, no problem.  I create a using statement for the reference, no problem.  I can even reference and use objects and methods from the reference.  As soon as I try to compile (F5), BAM!, Visual Studio doesn't understand the reference.  Ugh.

  • Anonymous
    March 22, 2011
    @Mark Spark - yup, i'm getting the exact same thing with VS2010. Go to compile -> suddenly the reference doesn't work and all the intellisense stops working as well - until the reference is removed and added. Just don't try to compile and life is great!

  • Anonymous
    April 13, 2011
    Great - short and simple steps thanks

  • Anonymous
    April 19, 2011
    Chris and Mark, I'm having the exact same problem as you are.  I am creating a WCF Library. Oddly, if I create a WCF application, it all works  fine. Very frustrating.

  • Anonymous
    April 20, 2011
    I suggest setting the Target framework of your project to the highest framework that uses your assembly. My error making assembly was set to .NET 4 while my project was set to the smaller .NET 4 Client Profile. That causes the same errors as those of Mark, Chris and Clayton. Changed the Framework to the Full/Extended Profile and everything compiled fine. If you have access to the source project then check if there are references that are not available in your Target Framework like System.Web.. Hope that fixes you errors too.

  • Anonymous
    June 05, 2011
    @Stefan: That was my problem too. The target framework of the reference proj was set to .NET 4 while the other was set to the .NET 4 Client Profile. Putting them both to .NET 4 solved the problem.

  • Anonymous
    July 21, 2011
    @Stefan: Thanks for this solution!  I've been struggling with this same problem for a while, and this is the first thing that's worked.

  • Anonymous
    August 09, 2011
    "The type or namespace name 'Security' does not exist in the namespace 'OPAL' (are you missing an assembly reference?) " why this error? how can i solve it?

  • Anonymous
    August 09, 2011
    Stefan Hoppe, that was genius ... thank you!

  • Anonymous
    August 21, 2011
    Sigh... and after all that I just noticed that the header at the top of the forum says C#.  If there's anyone out there with C++ background, VS2010, VS2008 and Cuda, maybe you could answer it anyway?  Thanks!

  • Anonymous
    August 21, 2011
    Did my post with all the info disappear?  I only see my comment I made AFTER posting the first one!

  • Anonymous
    August 21, 2011
    The comment has been removed

  • Anonymous
    October 03, 2011
    @Stefan Hoppe you saved my day....seems the WCF project by default set the Target framework to ".NET 4 Client Profile"

  • Anonymous
    September 24, 2012
    I was getting this issue.  Turns out the referencing project was pointed to .NET Framework 4 Client Profile.  I switched it to .NET Framework 4 and everything build fine.  Why is this the default framework?  It causes nothing but problems.

  • Anonymous
    November 27, 2012
    Looking at all these posts about the same issue, all references need to match, I am wondering why the heck MS doesn't tweak the error message to let the user know.  I also wasted a couple of hours on this stupid thing!!

  • Anonymous
    January 10, 2013
    The comment has been removed

  • Anonymous
    July 09, 2013
    Thank you very much for this post! It really solved my problem.

  • Anonymous
    July 17, 2013
    What to click?, what reference for GemBox? Please tell it to me, I really need this sir, reply in asap thank you for you nice post sir

  • Anonymous
    July 25, 2013
    Hellow Sir, My error is the type of namespace name 'claims' not exist. and I've tried to add it from reference but i can't get it. (I use both the .net tab and the browse tab) please help! Thanx

  • Anonymous
    March 12, 2014
    Why did I receive the error: "The type or namespace 'Resources' does not exist in the class or namespace 'WindowsFormsApplication1.Properties' (are you missing an assembly reference?)"


WHAT REFERENCE SHOULD I ADD?

  • Anonymous
    April 05, 2014
    using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using yo_lib;        if (!IsPostBack)        {            CategoryMasterClass objCTM = new CategoryMasterClass();            rpCatDetails.DataSource = objCTM.fn_getCategoryList();            rpCatDetails.DataBind();            if (Session["htProduct"] == null)            {                lblMasterSubTotal.Text = "0.00";                lblMasterTotal.Text = "0.00";                lblMasterVat.Text = "0.00";            }            else            {                ProductMasterClass objPM = new ProductMasterClass();                CoreWebList<ProductMasterClass> objProdList = new CoreWebList<ProductMasterClass>();                objProdList = objPM.fn_getHashProductByID(Session["htProduct"] as Hashtable);                if (objProdList == null)                {                    lblMasterSubTotal.Text = "0.00";                    lblMasterTotal.Text = "0.00";                    lblMasterVat.Text = "0.00";                }                else if(objProdList != null)                {                    for (int i = 0; i < objProdList.Count; i++)                    {                        subTotal = float.Parse(System.Math.Round((subTotal + float.Parse(((objProdList[i].dProductPrice) * (objProdList[i].pQuantity)).ToString())), 2).ToString());                    } Error:::::-----The type or namespace name 'yo_lib' could not be found (are you mission a using directive or an assemly referece?)

  • Anonymous
    May 26, 2014
    When you see issues with 10 years old, few positive satisfied answers (good luck), as in many other recurrent topics, the answer is nobody knows the true unique direct answer. (Did you update your Visual Studio, did you update connection types, did you....) If yes, you are in the oven. Try to use and old version or start again.

  • Anonymous
    July 30, 2014
    Error 1 The type or namespace name 'Linear' does not exist in the namespace 'Barcode' (are you missing an assembly reference?)ProjectRBBS SoftwareBarcodeBarcodeForm1.cs 59 14 Barcode

  • Anonymous
    September 05, 2014
    I am writing "using Microsoft.Phone.UserData;" and getting an error that Phone does not exist in namespace microsoft. I have rechecked the references and everything has been included. Where is it going wrong?

  • Anonymous
    August 13, 2015
    Check target framework from project properties

  • Anonymous
    November 24, 2015
    It doesn't Work sir. I got same Error again.

  • Anonymous
    November 24, 2015
    Use this following method to Avoid above error as Missing assembly reference. Sure this will solve your Bug. Step 1: Click the properties under Solution Explorer Step 2:Right click Resources.resx File. Its come under the Properties control. Step 3: Then click " Run Custom Tool " Step 4: Finished..... Then Run the bug will Solved.. Try this one Friends. Thank You Parameswaran R paramesram123@gmail.com

  • Anonymous
    January 21, 2016
    The references are listed and correct and to a .Net 4.0 library.  This project was developed in VS2013 as .Net 4.51.  But I needed to downgrade it to .Net 4.0.  After changing the target framework I deleted the Extension references and re-added them (they are 4.0 framework libraries).  My project will not compile now. Why not???