2010-12-14 4 views
5

내 응용 프로그램에 대한 사용자 지정 구성 섹션을 만들었습니다. 어떤 이유로 Visual Studio 2010에서 사용자 지정 속성을 선택할 수 없습니다. 나는 모든 "추가"키에 대해 다음과 유사한 경고를 받고 있어요 :App.Config 사용자 지정 구성 섹션 문제가 발생했습니다.

Could not find schema information for the element 'urlFilterSection' 

구성 파일 :

<configSections> 
    <section name="urlFilterSection" type="BotFinderApp.Models.UrlFilterSection, BotFinder" /> 
</configSections> 

<urlFilterSection> 
    <urlFilterCollection> 
     <add url="urlhere.com.au" numberOfIpsToExtract="10" /> 
     <add url="urlhere.com.au" numberOfIpsToExtract="10" /> 
     <add url="urlhere.com.au" numberOfIpsToExtract="10" /> 
     <add url="urlhere.com.au" numberOfIpsToExtract="10" /> 
     <add url="urlhere.com.au" numberOfIpsToExtract="10" /> 
     <add url="urlhere.com.au" numberOfIpsToExtract="10" /> 
     <add url="urlhere.com.au" numberOfIpsToExtract="10" /> 
     <add url="urlhere.com.au" numberOfIpsToExtract="10" /> 
     <add url="urlhere.com.au" numberOfIpsToExtract="10" /> 
    </urlFilterCollection> 
</urlFilterSection> 

UrlFilterSection :

namespace BotFinderApp.Models 
{ 
    public class UrlFilterSection : ConfigurationSection 
    { 
     public UrlFilterSection() 
     {  
     } 

     [ConfigurationProperty("urlFilterCollection", IsDefaultCollection = false)] 
     [ConfigurationCollection(typeof(UrlFilterCollection), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")] 
     public UrlFilterCollection Urls 
     { 
      get 
      { 
       var urlsCollection = (UrlFilterCollection)base["urlFilterCollection"]; 
       return urlsCollection; 
      } 
     } 
    } 
} 

UrlFilterCollection

namespace BotFinderApp.Models 
{ 
    public class UrlFilterCollection : ConfigurationElementCollection 
    { 
     public UrlFilterCollection() 
     { 
     } 

     protected override ConfigurationElement CreateNewElement() 
     { 
      return new UrlFilter(); 
     } 

     protected override object GetElementKey(ConfigurationElement element) 
     { 
      return ((UrlFilter)element).Url; 
     } 
    } 
} 

UrlFilter

namespace BotFinderApp.Models 
{ 
    public class UrlFilter : ConfigurationElement 
    { 
     public UrlFilter() 
     { 
     } 

     [ConfigurationProperty("url", DefaultValue = "", IsRequired = true)] 
     public string Url 
     { 
      get { return (string)this["url"]; } 
      set { this["url"] = value; } 
     } 

     [ConfigurationProperty("numberOfIpsToExtract", DefaultValue = "0", IsRequired = true)] 
     public int NumberOfIpsToExtract 
     { 
      get { return (int)this["numberOfIpsToExtract"]; } 
      set { this["numberOfIpsToExtract"] = value; } 
     } 
    } 
} 
+1

응용 프로그램에서 사용할 수 있습니까? 내 말은, 단지 시간 경고를 컴파일하는 것입니까, 아니면 응용 프로그램에서 사용할 수없는 것입니까? – decyclone

+0

UrlFilterCollection serviceConfigSection = ConfigurationManager.GetSection ("urlFilterSection")을 UrlFilterCollection으로 사용합니다. 반환 ... – timothyclifford

답변

3

문제 찾았

Decyclone은 정확했다가, 오류가 단지 시간의 경고를 컴파일 사실에 있었다. 그것은이

UrlFilterSection serviceConfigSection = ConfigurationManager.GetSection("urlFilterSection") as UrlFilterSection; 

같이 있었어야 할 때

UrlFilterCollection serviceConfigSection = ConfigurationManager.GetSection("urlFilterSection") as UrlFilterCollection; 

하는 당신에게 FlipScript 및 Decyclone :

UPDATE 감사 : 진짜 문제는이 같은 내 구성을 접근이었다

:

나는 컴파일 타임 경고를 제거하는 방법을 발견했다 - 나는 usin이다. g Visual Studio 2010. 사용자 지정 구성 섹션을 만든 후 구성 파일에 대한 스키마 파일을 생성하는 도구 모음에서 "Create Schema"단추를 사용했습니다. 나는 이것을 프로젝트에 저장했고 경고는 사라졌다.

관련 문제