1

I'm trying to save a path as a string to my application settings in VB.net but I'm getting an error when I'm running my code. I attached an image showing the error that I'm getting (Configuration system failed to initialize) Error Message I tried looking all around for a solution but nothing worked so far.

Appplication Settings enter image description here

Here is my code in the form1

Public Class Form1
   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       txtSavePath.Text = GetSavePath()
   End Sub


   Private Function GetSavePath() As String
       Try
           If My.Settings.SavePath = Nothing Then
               Return ""
           Else
               Return My.Settings.SavePath
           End If
       Catch ex As Exception
           MessageBox.Show(ex.Message, "Error",
               MessageBoxButtons.OK,
               MessageBoxIcon.Error)
       End Try
   End Function
   Private Sub SetSavePath(path As String)
       Try
           My.Settings.SavePath = path
           My.Settings.Save()
       Catch ex As Exception
           MessageBox.Show(ex.Message, "Error",
               MessageBoxButtons.OK,
               MessageBoxIcon.Error)
       End Try
   End Sub
End Class

This is what visual studio generated for App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" >
            <section name="test.My.MySettings" type="System.Configuration.ClientSettingsSection, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>
    <userSettings>
        <test.My.MySettings>
            <setting name="SavePath" serializeAs="String">
                <value />
            </setting>
        </test.My.MySettings>
    </userSettings>
</configuration>

  • It is a "it did not work" message, without the stack trace of the exception we can't tell you anything. Do watch out for this kind of error reporting, displaying the Exception.Message is not enough. Try this again, but this time give the project a good name. Minimizes the odds that it accidentally loads the settings file of a previous "test" project. – Hans Passant Jun 30 '21 at 02:05
  • Take a look at: [Configuration System Failed to Initialize](https://stackoverflow.com/questions/6436157/configuration-system-failed-to-initialize) – Xingyu Zhao Jun 30 '21 at 02:21
  • I believe this has something to do with .net 5. Most of the examples for 5 are in C#. – Mary Jul 06 '21 at 05:39

0 Answers0