Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3239496
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:58:37+00:00 2026-05-17T17:58:37+00:00

I have a Visual Basic .Net 2.0 program. I’m moving the settings from an

  • 0

I have a Visual Basic .Net 2.0 program. I’m moving the settings from an older settings file, to an app.config program settings file. I’m trying to do this as nicely as possible.

So, I added my setting as shown in this image.

On load I do this:

If My.Settings.databaseConnectionSettings Is Nothing Then
            My.Settings.databaseConnectionSettings = New ArrayList()
End If

This is my custom class:

Imports System.Xml.Serialization

<Serializable()> Public Class DatabaseConnectionSettings
    Private _nickname As String = String.Empty
    Private _username As String = String.Empty
    Private _password As String = String.Empty
    Private _database As String = String.Empty
    Private _server As String = String.Empty
    Private _ssl As Boolean

    Public Sub New()
        _nickname = ""
        _username = ""
        _password = ""
        _database = ""
        _server = ""
        _ssl = False
    End Sub

    Public Sub New(ByVal nickname As String, ByVal username As String, _
                   ByVal password As String, ByVal database As String, _
                   ByVal server As String, ByVal ssl As Boolean)
        _nickname = nickname
        _username = username
        _password = password
        _database = database
        _server = server
        _ssl = ssl
    End Sub

    Public Property nickname() As String
        Get
            Return _nickname
        End Get
        Set(ByVal Value As String)
            _nickname = Value
        End Set
    End Property

    Public Property username() As String
        Get
            Return _username
        End Get
        Set(ByVal Value As String)
            _username = Value
        End Set
    End Property

    Public Property password() As String
        Get
            Return _password
        End Get
        Set(ByVal Value As String)
            _password = Value
        End Set
    End Property

    Public Property database() As String
        Get
            Return _database
        End Get
        Set(ByVal Value As String)
            _database = Value
        End Set
    End Property

    Public Property server() As String
        Get
            Return _server
        End Get
        Set(ByVal Value As String)
            _server = Value
        End Set
    End Property

    <XmlElementAttribute(ElementName:="ssl")> Public Property ssl() As Boolean
        Get
            Return _ssl
        End Get
        Set(ByVal Value As Boolean)
            _ssl = Value
        End Set
    End Property

End Class

And, this is how I use it:

Dim databaseSettings As New DatabaseConnectionSettings( _
                        Me.txtNickName.Text, Me.txtUser.Text, Me.txtPass.Text, Me.txtData.Text, _
                            Me.txtServer.Text, Me.chkSSL.Checked)
                        'This statement will increment the arraylist count'
                        My.Settings.databaseConnectionSettings.Add(databaseSettings)
                        'This statement will save everything but the array list'
                        My.Settings.Save()
                        'This statement reloads everything, but the array list.  The array list count after this goes to zero.'
                        My.Settings.Reload() 'If I remove this, program works fine until next run.'

So, the question is, how do I get that arraylist of my DatabaseConnectionSettings saved to persistent storage? I want to do this in the cleanest way possible. That is, I don’t want to have to convert it to a string or save it to a separate file every-time I want to use it. I would like to be able to use the My.Settings accessor method.

Note, it’s working perfectly, except it’s not being saved to storage.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:58:37+00:00Added an answer on May 17, 2026 at 5:58 pm

    Debug + Exceptions, tick the Thrown box for CLR exceptions. You’ll now see what is going wrong. There are several exceptions but the deal breaker is the second one, “The type … was not expected”.

    Attributes are required to tell the xml serializer what types are stored in an ArrayList. This is described in this MSDN Library page, “Serializing an ArrayList” section. Problem is, you cannot apply the required [XmlElement] attribute since the ArrayList instance is declared in auto-generated code. A generic List(Of T) doesn’t have the same problem, but now you’ll smack into a restriction in the setting designer, it doesn’t support generic types.

    Well, a rock and a hard place here, you can’t make this work. StringCollection is the distasteful alternative. Or ditch the idea of using Settings for this and just do it yourself with xml serialization. Or whatever else you prefer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing a windows form based project in visual basic .NET, moving
I'm fairly new to Visual Studio (specifically Visual Basic .NET) but have been programming
I have a ASP .Net web appliaction written in Visual Basic .Net running on
This works (Visual Basic .NET) but seems comically long with all the LINQ to
Summary I have written an Excel wrapper in .NET using Visual Basic and Visual
I recently moved from Visual Basic 6 to C# 2010 .NET. In Visual Basic
I there I have this scenario: a) Notebook :Windows Server 2008 R1, Visual basic
I have a big application written in Visual Basic 6 and I need to
The last GUI programming I have done was with Visual Basic, which included objects
Goal: Provide a web service using Visual Basic or C# or .NET that interacts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.