Custom Configuration Section : Impossible d'initialiser le type
Bonjour Tous,
Je peine a créer une configuration personnalisée.
Voici le app.config que je souhaite obtenir:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="WorkingSpaceSection" type ="WorkingSpaceConfig.WorkingSpaceConfigurationSection , WorkingSpaceConfig "/>
</configSections>
<WorkingSpaceSection >
<FoldersGroup>
<Folder Topic ="TEST">
<Directory fullpath="D:\DataTemp\" Extension=".txt"/>
<ShellToExecute fullpath="D:\SendTo.bat" />
</Folder>
<Folder Topic ="PROD">
<Directory fullpath="D:\DataService\" Extension=".cmd"/>
<ShellToExecute fullpath="D:\Execute.bat" />
</Folder>
</FoldersGroup>
</WorkingSpaceSection> |
Et dans la DLL qui contient les config, je crée les éléments:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
public class DirectoryElement : ConfigurationElement
{
[ConfigurationProperty("fullpath", DefaultValue = ".", IsRequired = true)]
public String Fullpath
{
get { return (String)this["fullpath"]; }
set { this["fullpath"] = value; }
}
[ConfigurationProperty("Extension", DefaultValue = ".req", IsRequired = true)]
public String Extension
{
get { return (String)this["extension"]; }
set { this["extension"] = value; }
}
}
public class ShellToExecuteElement : ConfigurationElement
{
[ConfigurationProperty("ShellToExecute", DefaultValue = ".", IsRequired = true)]
public String Fullpath
{
get
{
return (String)this["fullpath"];
}
set
{
this["fullpath"] = value;
}
}
}
public class FolderElement : ConfigurationElement
{
[ConfigurationProperty("Directory", IsRequired = true)]
public DirectoryElement Directory
{
get { return (DirectoryElement)this["Directory"]; }
set { this["Directory"] = value; }
}
[ConfigurationProperty("ShellToExecute", IsRequired = true)]
public ShellToExecuteElement ShellToExecute
{
get { return (ShellToExecuteElement)this["ShellToExecute"]; }
set { this["ShellToExecute"] = value; }
}
[ConfigurationProperty("Topic", IsRequired = true)]
public String Topic
{
get {return (String)this["Topic"];}
set{ this["Topic"] = value;}
}
}
[ConfigurationCollection(typeof(FolderElement), CollectionType = ConfigurationElementCollectionType.BasicMap)]
public class FolderCollection : ConfigurationElementCollection
{
internal const string PropertyName = "Folder";
public FolderElement this[int index]
{
get
{
return base.BaseGet(index) as FolderElement;
}
}
public new FolderElement this[string key]
{
get { return (FolderElement)BaseGet(key); }
}
protected override System.Configuration.ConfigurationElement CreateNewElement()
{
return new FolderElement();
}
protected override object GetElementKey(System.Configuration.ConfigurationElement element)
{
return ((FolderElement)element).Topic;
}
protected override bool IsElementName(string elementName)
{
return elementName.Equals(PropertyName, StringComparison.InvariantCultureIgnoreCase);
}
protected override string ElementName
{
get { return PropertyName; }
}
public override bool IsReadOnly()
{
return false;
}
}
public class WorkingSpaceConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("FoldersGroup")]
public FolderCollection FoldersGroup
{
get { return (FolderCollection)base["FoldersGroup"]; }
set { this["FoldersGroup"] = value; }
}
} |
-
Dans le Main.cs de l'exécutable, je fais:
Code:
config.GetSection("WorkingSpaceSection");
Erreur:
Citation:
Une erreur s'est produite lors de la création du gestionnaire de section de configuration pour WorkingSpaceSection : Impossible de charger le type