我发现了"缺少using指令或程序集引用"没有线索什么错 [英] I'm getting the "missing a using directive or assembly reference" and no clue what's going wrong

查看:388
本文介绍了我发现了"缺少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指令或程序集refenrence错误,每当我尝试运行我的应用程序。我已经看了看其他时候这个问题已经被问,似乎无法找出我要去哪里错了。事情是,我非常新的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(); 
                }      
            }  
}
}  '

任何帮助是pciated AP $ P $

Any help is appreciated

推荐答案

您可能没有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.

检查,看它是否是你引用...

右键单击并选择Add Reference ...

在.NET程序集的列表中找到System.Configuration,选择它,然后单击确定...

组装现在应该会出现在你的介绍人......

这篇关于我发现了&QUOT;缺少using指令或程序集引用&QUOT;没有线索什么错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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