Problème d'utilisation de "configurationSection" & App.config
Bonjour à toutes et à tous !
Voilà mon soucis :
Jusqu'à présent, j'utilisais pour de la config les paramètres "userSettings"... aucun problèmes pour l'utilisation.
Maintenant, j'aimerai changer ma façon de faire, en utilisant "configurationSection"... j'ai regardé un peu partout sur le net, mais impossible de récupérer les infos provenant de mon app.config ...
Du coup, je vous montre mon code que j'ai simplifié au max pour essayer de le faire fonctionner, mais rien à faire...
Donc ma petite appli de test se résume à une form avec un label :
Coté form :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| Public Class Form1
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Dim config As MyConfigSectionHandler.MyHandler = New MyConfigSectionHandler.MyHandler()
Label1.Text = config.MyAttrib1.ToString()
End Sub
End Class |
côté classe surchargée qui doit récupérer les paramètres
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
| Imports System
Imports System.Collections
Imports System.Text
Imports System.Configuration
Imports System.Xml
Public Class MyHandler
Inherits ConfigurationSection
Public Sub MyHander()
End Sub
Public Sub MyHander(ByVal attribVal As String)
MyAttrib1 = attribVal
End Sub
<ConfigurationProperty("myAttrib1", DefaultValue:="voiture", IsRequired:=True)> _
<StringValidator(InvalidCharacters:="~!@#$%^&*()[]{}/;'\|\\", MinLength:=1, MaxLength:=60)> _
Public Property MyAttrib1() As String
Get
Return CStr(Me("myAttrib1"))
End Get
Set(ByVal value As String)
Me("myAttrib1") = value
End Set
End Property
End Class |
et enfin le fichier de config app.conf :
Code:
1 2 3 4 5 6 7
| <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="testConfiguration" type="WindowsApplication1.MyHandler, WindowsApplication1" />
</configSections>
<testConfiguration myAttrib1="camion" />
</configuration> |
Et donc quand j'éxecute, j'ai toujours "voiture" et non "camion"...
Merci d'avance de m'éclaircir, car là je sèche :bug: