2012-10-30 21 views
11

Próbuję utworzyć niestandardową sekcję konfiguracji, aby załadować listę "piekarników" monitorów mojej aplikacji. To jest moje pierwsze doświadczenie z sekcjami konfiguracji i starałem się podążać za przykładami; ale nie mogę zrozumieć, czego mi brakuje.Nie mogę uzyskać sekcji konfiguracji niestandardowej

Kiedy próbuję dostać się do sekcji config pojawia się następujący wyjątek:

Wystąpił błąd podczas tworzenia programu obsługi sekcji konfiguracji Burnin: Nie można załadować typu „BurnIn.UI.BurnInConfigurationSection” z zespołem „Systemu .Configuration, wersja = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a '. (C: \ MKS \ Burnin \ PC_SW \ bin \ BurnIn.UI.vshost.exe.config linia 8)

W moim głównym Próbowałem: System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel .Żaden); if (config.Sections [BurnInSection] == null) ...

BurnInConfigurationSection burnInConfigSection = config.GetSection(BurnInSection) as BurnInConfigurationSection; 

BurnInConfigurationSection burnInConfigSection = ConfigurationManager.GetSection(BurnInSection) as BurnInConfigurationSection; 

Wszystko wydaje się prowadzić do tego samego wyjątku

Kiedy patrzę na config.FilePath jest to „C: \ MKS Plik \ BurnIn \ PC_SW \ bin \ BurnIn.UI.vshost.exe.config ", który sprawdziłem, pasuje do pliku app.config.

Oto moje zajęcia konfiguracji:

namespace BurnIn.UI 
{ 
/// <summary> 
/// BurnIn Application configuration section in app.config 
/// </summary> 
public class BurnInConfigurationSection : ConfigurationSection 
{ 
    [ConfigurationProperty("Ovens", IsDefaultCollection = false)] 
    [ConfigurationCollection(typeof(OvenCollection), 
     AddItemName = "add", 
     ClearItemsName = "clear", 
     RemoveItemName = "remove")] 
    public OvenCollection Ovens 
    { 
     get { return (OvenCollection)base["Ovens"]; } 
     set { base["Ovens"] = value; } 
    } 
} 

/// <summary> 
/// Oven configuration information 
/// </summary> 
public class OvenConfig : ConfigurationElement 
{ 
    public OvenConfig() { } 

    public OvenConfig(string nickName, string mesName, string ip, int slotCount) 
    { 
     NickName = nickName; 
     MesName = mesName; 
     IP = ip; 
     SlotCount = slotCount; 
    } 

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

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

    [ConfigurationProperty("IP", DefaultValue = "10.130.110.20", IsRequired = true, IsKey = false)] 
    public string IP 
    { 
     get { return (string)this["IP"]; } 
     set { this["IP"] = value; } 
    } 

    [ConfigurationProperty("SlotCount", DefaultValue = "20", IsRequired = true, IsKey = false)] 
    public int SlotCount 
    { 
     get { return (int)this["SlotCount"]; } 
     set { this["SlotCount"] = value; } 
    } 

} 
/// <summary> 
/// Collection of Oven Configs 
/// </summary> 
public class OvenCollection : ConfigurationElementCollection 
{ 
    public OvenCollection() 
    { 
    } 

    public OvenConfig this[int index] 
    { 
     get { return (OvenConfig)BaseGet(index); } 
     set 
     { 
      if (BaseGet(index) != null) 
      { 
       BaseRemoveAt(index); 
      } 
      BaseAdd(index, value); 
     } 
    } 

    public void Add(OvenConfig ovenConfig) 
    { 
     BaseAdd(ovenConfig); 
    } 

    public void Clear() 
    { 
     BaseClear(); 
    } 

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

    protected override object GetElementKey(ConfigurationElement element) 
    { 
     return ((OvenConfig)element).NickName; 
    } 

    public void Remove(OvenConfig ovenConfig) 
    { 
     BaseRemove(ovenConfig.NickName); 
    } 

    public void RemoveAt(int index) 
    { 
     BaseRemoveAt(index); 
    } 

    public void Remove(string name) 
    { 
     BaseRemove(name); 
    } 
} 
} 

Oto mój app.config:

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
     <section name="Biotronik.NGMP.DAL.Sources.DalBaseSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </sectionGroup> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> 
    <section name="BurnIn" type="BurnIn.UI.BurnInConfigurationSection"/> 
    </configSections> 
    <applicationSettings> 
    <Biotronik.NGMP.DAL.Sources.DalBaseSettings> 
     <setting name="ConfigFileName" serializeAs="String"> 
     <value>DalConfig.xml</value> 
     </setting> 
     <setting name="MappingFileName" serializeAs="String"> 
     <value>BurnInTestPlanMap.tpx</value> 
     </setting> 
    </Biotronik.NGMP.DAL.Sources.DalBaseSettings> 
    </applicationSettings> 
    <connectionStrings> 
    <add name="BurnInConnection" connectionString="metadata=res://*/BurnIn.csdl|res://*/BurnIn.ssdl|res://*/BurnIn.msl;provider=Oracle.DataAccess.Client;provider connection string=&quot;DATA SOURCE=XXXX;PASSWORD=xxxx;PERSIST SECURITY INFO=True;USER ID=XXXX&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <log4net configSource="BurnInLog4net.config"/> 
    <BurnIn> 
    <Ovens> 
     <add NickName="Mark's Oven" MesName="MESBOven" IP="10.130.110.20" SlotCount="5"/> 
     <add NickName="Real Oven" MesName="MESOven1" IP="10.130.110.50" SlotCount="20"/> 
    </Ovens> 
    </BurnIn> 
    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> 
</configuration> 

Odpowiedz

23

Chyba wprowadziły złą nazwę konfiguracji typu sekcja tutaj:

<section name="Biotronik.NGMP.DAL.Sources.DalBaseSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

Powinieneś użyć nazwy niestandardowej konfiguracji n typ sekcji tutaj:

type="BurnIn.UI.BurnInConfigurationSection, AssemblyWhereThisTypeIsDeclared" 
+0

Ta sekcja dotyczy innej biblioteki DLL, której używam. Ten, który próbuję załadować, to: Co używam do YourAssembly? – markshancock

+0

@markshancock następnie podaj nazwę zespołu, w którym "BurnInConfigurationSection" jest zadeklarowany –

+0

Jest zdefiniowany w pliku App.xaml.cs w głównym zespole aplikacji (BurnIn.UI) – markshancock

Powiązane problemy