首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我收到“缺少using指令或程序集引用”的提示,却不知道出了什么问题

我收到“缺少using指令或程序集引用”的提示,却不知道出了什么问题
EN

Stack Overflow用户
提问于 2013-06-27 21:18:38
回答 10查看 199.6K关注 0票数 21

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

每当我尝试运行我的应用程序时,我总是收到“are you missing a using指令”或“程序集引用”错误。我看过其他被问到这个问题的时候,似乎找不出我错在哪里。问题是,我是Visual Studio的新手,对可能的答案一无所知。

下面是生成错误的类文件。我希望我已经包括了你需要帮助我的一切。谢谢。

代码语言:javascript
复制
 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(); 
                }      
            }  
}
}  '

任何帮助我们都将不胜感激

EN

回答 10

Stack Overflow用户

回答已采纳

发布于 2013-06-27 21:22:20

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

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

看看你的推荐信里有没有...

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

在.Net程序集列表中找到System.Configuration,选择它,然后单击Ok...

程序集现在应该出现在您的引用中...

票数 28
EN

Stack Overflow用户

发布于 2017-04-20 13:54:43

引用dll的.Net框架应与引用dll的项目的.Net框架版本相同

票数 10
EN

Stack Overflow用户

发布于 2022-02-07 19:19:31

如果您尝试过上述解决方案,但没有找到答案,请确保所有项目的.NET版本都是相同的。

在将.NET版本4.6.1导入到.NET版本4.6.2项目中时,我遇到了这个问题。没有任何来自Visual Basic的警告!

更多信息:The type or namespace name could not be found

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17344295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档