Visual Studio warning configuration element is not declared

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..
vb.net app.config
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
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
view raw MyConfigs.vb hosted with ❤ by GitHub

Popular posts from this blog

VB .NET DropBox Api Source Code Example

VB .NET Google Drive Api Source Code Example

VB.NET Access 2007 Hierarchical TreeView

VB.NET How to properly close a windows application Form

DAO in VB .NET MS ACCESS Database

Solution - There is already an open DataReader associated with this Command which must be closed first.