Nathon Dalton

Custom Data Types for Settings.settings

The Problem

I would like to have a setting in my project's settings.settings file that uses a custom data type I create. The data type will have three values that will be more specific to the project I'm creating than generic integers, strings, etc. The new datatype I want to create is going to be the mode in which the application should start. There are three modes, "Running", "Stopped" or "LastMode".

I have created a new class library project with a single class in it called Settings.vb. That file contains the code below. This file is referenced by the main project. I just thought using a seperate class library would be cleaner to put all my structures, generic classes, enumerations and things of that sort in and just reference it in the main project.

ClassLibrary - Settings.vb

Namespace Settings

Public Class TFWSettings

Public Enum Modes



End Enum

Public Enum StartupModes




End Enum

End Class

End Namespace

Intended Outcome

The intended outcome is that I would be able to select from the three options in the "StartupModes" enumeration in the Types field of the main project's Settings.settings file. Of course, I will have to browse to select the correct class from the Type field's "Browse..." option in the drop down menu. Given that the class library project is referenced, I should be able to select the enumeration as the type.

What I've Done So Far

I am unable to get the Class Library's settings file to even show up when I select browse from within the Settings.settings' Type menu. Here's exactly what I'm doing.

  • Open the Solution Explorer (CTRL+ALT+L)
  • Expand your project in the Solution Explorer
  • Double click on the My Project folder under your project
  • Add the class library as a reference in the main project
    • Click on the References tab
    • Click on the down arrow on the Add button
    • Click Reference from the menu that drops down
    • Click the Projects tab
    • Select the class library project
    • Click OK
  • Import the namespace
    • Find the "Imported namespaces" box at the bottom of the References tab
    • Scroll to the bottom of the list
    • Check the box that says "ClassLibrary.Settings"
  • Add the setting with the "StartupModes" custom type
    • Click on the Settings tab on the left
    • Type the name of the new setting
    • Select "Browse..." from the bottom of the Type drop down menu
    • Try to find the classlibrary.settings type, but it's not there...


How do I get a custom type created and how do I make it selectable in the Type drop down in the Settings tab in the My Projects area of my main project I would REALLY appreciate any help that anyone can give me!! Thank you in advance!

Re: Visual Basic General Custom Data Types for Settings.settings

Bruno Yu - MSFT

Nathon Dalton,

According to the desciption, I reproduce all the steps in VB 2005 Express Edition. However, I can add the ClassLibrary1.Settings with the TFWSettings class in my Settings.settings -> Type -> Browse... -> Select a Type panel.

Then in the form.vb code file, I can import the ClassLibrary1, make an instance of ClassLibrary1.Settings.TFWSettings. Then I can see the StartupModes enum and the member such as Running in the IntelliSence. It seems that your steps fows the correct way to add the custome type in the application by adding reference for the class library.

In Settings.Designer.vb code, I can see the related code snippet added as follows:

Code Block

<Global.System.Configuration.UserScopedSettingAttribute(), _

Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _

Public Property Setting() As Global.ClassLibrary1.Settings.TFWSettings


Return CType(Me("Setting"),Global.ClassLibrary1.Settings.TFWSettings)

End Get


Me("Setting") = value

End Set

End Property

I would like to provide you the following thread and artice that can help you to understand the problem better:

ConfigurationSection Question

Application Settings

Hope that can help you.