我收到“缺少 using 指令或程序集引用"的提示不知道出了什么问题 [英] I'm getting the "missing a using directive or assembly reference" and no clue what's going wrong

查看:19
本文介绍了我收到“缺少 using 指令或程序集引用"的提示不知道出了什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试允许用户将数据输入到将添加到 web.config 文件的文本框中.我已将相关行添加到 web.config 文件中,但是当我创建此类时,一切都出错了.

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.

每当我尝试运行我的应用程序时,我不断收到您是否缺少 using 指令或程序集引用错误.我已经看过其他时候有人问过这个问题,但似乎无法弄清楚我哪里出错了.问题是我对 Visual Studio 非常陌生,对可能的答案一无所知.

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(); 
                }      
            }  
}
}  '

感谢任何帮助

推荐答案

您可能没有将 System.Configuration dll 添加到项目引用中.默认情况下不存在,您必须手动添加.

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.

右键单击引用并在 .net 程序集中搜索 System.Configuration.

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

检查它是否在您的参考文献中...

右键单击并选择添加引用...

在 .Net Assemblies 列表中找到 System.Configuration,选中它,然后点击 Ok...

程序集现在应该出现在您的参考文献中...

这篇关于我收到“缺少 using 指令或程序集引用"的提示不知道出了什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆