[c#] I'm getting the "missing a using directive or assembly reference" and no clue what's going wrong

I'm trying to allow a user to enter data into a textbox that will be added to the web.config file. I've added the relevent lines to the web.config file but when I make this class all goes wrong.

I keep getting the are you missing a using directive or assembly refenrence error whenever I try to run my app. I have looked at the other times this question has been asked and can't seem to figure out where I'm going wrong. The thing is that I am extremely new to Visual Studio and am just left blank at what could be the answer.

Below here is the class file that's generating the error. I hope I've included everything you need to assist me. Thank you.

 using System.Collections.Generic;
 using System.Linq;
 using System.Configuration; 


namespace WebConfigDemo
{    
public class CompanyConfigSection : ConfigurationSection   
{       
    [ConfigurationProperty("", IsRequired = true, IsDefaultCollection = true)]   
    public CompanyConfigCollection Companies       
    {
        get           
        {              
        return (CompanyConfigCollection)this[""];           
        }            
        set            
        {            
            this[""] = value;            
        }       
    }   
}     
public class CompanyConfigElement : ConfigurationElement   
{      
                [ConfigurationProperty("id", IsKey = true, IsRequired = true)]        
    public int Id        
                {            
                    get      
                {                
                        return (int)this["id"];            
                    }            
                    set           
                    {               
                        this["id"] = value;          
                }    
                }         
    [ConfigurationProperty("name", IsRequired = true)]        
    public string Name        
    {            
        get           
        {            
                    return this["name"].ToString();            
        }           
        set           
        {               
            this["name"] = value;           
        }    

    }   
} ' 
public class CompanyConfigCollection : ConfigurationElementCollection    
{       
    protected override ConfigurationElement CreateNewElement()     
{          
    return new CompanyConfigElement();       
    }       
    protected override object GetElementKey(ConfigurationElement element)     
    {          
        return ((CompanyConfigElement)element).Id;        
    }   
}    
public class CompaniesConfig   
{    
            private static readonly Dictionary<int, CompanyConfigElement> 
                Elements;         
    static CompaniesConfig()       
    {         
                Elements = new Dictionary<int, CompanyConfigElement>();       
                var section = (CompanyConfigSection)ConfigurationManager.GetSection          ("companies");           
                foreach (CompanyConfigElement system in section.Companies)        
                    Elements.Add(system.Id, system);       
    }        
    public static CompanyConfigElement GetCompany(int companyId)       
    {          
                        return Elements[companyId];   
    }      
            public static List<CompanyConfigElement> Companies        
            {          
                get
                {
                    return Elements.Values.ToList(); 
                }      
            }  
}
}  '

Any help is appreciated

This question is related to c# asp.net asp.net-mvc visual-studio-2010

The answer is


You probably don't have the System.Configuration dll added to the project references. It is not there by default, and you have to add it manually.

Right-click on the References and search for System.Configuration in the .net assemblies.

Check to see if it is in your references...

enter image description here

Right-click and select Add Reference...

enter image description here

Find System.Configuration in the list of .Net Assemblies, select it, and click Ok...

enter image description here

The assembly should now appear in your references...

enter image description here


This problem would be caused by your application missing a reference to an external dll that you are trying to use code from. Usually Visual Studio should give you an idea about which objects that it doesn't know what to do with so that should be a step in the right direction.

You need to look in the solution explorer and right click on project references and then go to add -> and look up the one you need. It's most likely the System.Configuration assembly as most people have pointed out here while should be under the Framework option in the references window. That should resolve your issue.


In some cases, when necessary using has been obviously added and studio can't see this namespace, studio restart can save the day.


Your using statements appear to be correct.

Are you, perhaps, missing the assembly reference to System.configuration.dll?

Right click the "References" folder in your project and click on "Add Reference..."


The following technique worked for me:

1) Right click on the project Solution -> Click on Clean solution

2) Right click on the project Solution -> Click on Rebuild solution


I had the same problem earlier today. I could not figure out why the class file I was trying to reference was not being seen by the compiler. I had recently changed the namespace of the class file in question to a different but already existing namespace. (I also had using references to the class's new and previous namespaces where I was trying to instantiate it)

Where the compiler was telling me I was missing a reference when trying to instantiate the class, I right clicked and hit "generate class stub". Once Visual Studio generated a class stub for me, I coped and pasted the code from the old class file into this stub, saved the stub and when I tried to compile again it worked! No issues.

Might be a solution specific to my build, but its worth a try.


.Net framework of the referencing dll should be same as the .Net framework version of the Project in which dll is referred


I have observed a quote ' in your 1st line and also at the end of your last line.

'using System.Collections.Generic;

Is this present in your original code or some formatting mistake?


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to asp.net-mvc

Using Lato fonts in my css (@font-face) Better solution without exluding fields from Binding Vue.js get selected option on @change You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to send json data in POST request using C# VS 2017 Metadata file '.dll could not be found The default XML namespace of the project must be the MSBuild XML namespace How to create roles in ASP.NET Core and assign them to users? The model item passed into the dictionary is of type .. but this dictionary requires a model item of type How to use npm with ASP.NET Core

Examples related to visual-studio-2010

variable is not declared it may be inaccessible due to its protection level SSIS Excel Connection Manager failed to Connect to the Source This project references NuGet package(s) that are missing on this computer Gridview get Checkbox.Checked value error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj What is the difference between Visual Studio Express 2013 for Windows and Visual Studio Express 2013 for Windows Desktop? Attach (open) mdf file database with SQL Server Management Studio What is and how to fix System.TypeInitializationException error? Could not load file or assembly "Oracle.DataAccess" or one of its dependencies IIS error, Unable to start debugging on the webserver