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

214,187

Solution 1

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

Solution 2

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

Solution 3

If you've tried the above solutions and haven't found the answer, make sure that the .NET versions of all projects are the same.

I ran into this problem when importing a .NET version 4.6.1 into a .NET version 4.6.2 project. Without any warnings from Visual Basic!

More Info: The type or namespace name could not be found

Solution 4

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..."

Share:
214,187

Related videos on Youtube

Scubacode
Author by

Scubacode

Updated on July 09, 2022

Comments

  • Scubacode
    Scubacode almost 2 years

    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

    • ic3b3rg
      ic3b3rg almost 11 years
      Which line generates the error?
    • Microsoft DN
      Microsoft DN almost 11 years
      Can you tell us where are yu getting the error
    • Felix Aballi
      Felix Aballi almost 8 years
      Guidance: 1) assembly loaded?, 2) assembly loaded matches with origin assembly?, 3) "using" directives pointing to old or none valid references?, 4) .csproj manifest includes source invalid?, 5) a search tool looking regex in the entire solution (every class library and project). 5) check project settings for net framework version build option (collaborate in teams bring on this kind of problen, you must agree net framew. build version in both sides) 6) After that clean and build each by separate and finally, include all references to the destination project/class library. I should work!
  • Abijeet Patro
    Abijeet Patro almost 11 years
    Yes, this is probably the reason why.
  • Lucas
    Lucas almost 11 years
  • Scubacode
    Scubacode almost 11 years
    no it's not, new to this site and got a pop up saying to add them in so it would format correctly in my question
  • Scubacode
    Scubacode almost 11 years
    Will the system.configuration.dll already be there? sorry, such a noob. Does Visual Studio create the dll for you?
  • Samuel Parkinson
    Samuel Parkinson almost 11 years
    @Scubacode Looks like John Kraft has provided some great images on where to find the assembly!
  • Felix Aballi
    Felix Aballi almost 8 years
    Guidance: 1) assembly loaded?, 2) assembly loaded matches with origin assembly?, 3) "using" directives pointing to old or none valid references?, 4) .csproj manifest includes source invalid?, 5) a search tool looking regex in the entire solution (every class library and project). 5) check project settings for net framework version build option (collaborate in teams bring on this kind of problen, you must agree net framew. build version in both sides) 6) After that clean and build each by separate and finally, include all references to the destination project/class library. I should work!