Visual Studio warning configuration element is not declared
Visual Studio warning configuration element is not declared
![]() |
Visual Studio warning |
Error
- When you open your Visual Basic Project, and navigate to App.config file for editing, you notice that <configuration> is underlined with blue line. When the cursor hovers, you see this message ( The 'configuration' element is not declared ).
![]() |
configuration element is not declared |
Solution
- Open your VB.Net Project.
- From XML menu, choose Schemas..
![]() |
App.Config - configuration element solution |
- From XML Schemas, look for DotNetConfig.xsd
- From Dropdown Use, choose Use this schema
- Click OK.
![]() |
vb.net - app.Config - configuration solution |
Create your own App.config file, Set Value, Get Value
- You need to add reference to Configuration.dll in your project.
- Create Class MyConfigs.vb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.Configuration | |
Imports System.Reflection | |
Public Class MyConfigs | |
Private _config As Configuration | |
Private _settings As AppSettingsSection | |
Public Function GetProperty(propertyName As String) As String | |
Return _settings.Settings.Item(propertyName).Value | |
End Function | |
Public Sub SetProperty(propertyName As String, propertyValue As String) | |
_settings.Settings.Item(propertyName).Value = propertyValue | |
End Sub | |
Public Sub New() | |
_config = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location) | |
_settings = _config.AppSettings | |
End Sub | |
Protected Overrides Sub Finalize() | |
MyBase.Finalize() | |
_config.Save(ConfigurationSaveMode.Modified) | |
End Sub | |
End Class | |
'How to create config from Form | |
Public Class MainForm | |
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load | |
Dim _appConfig As New AppConfig | |
_appConfig.SetProperty(propertyName, propertyValue) | |
_appConfig.GetProperty(propertyName) | |
End Sub | |
End Class |