Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. My.Settings won't serialize my class

My.Settings won't serialize my class

Scheduled Pinned Locked Moved Visual Basic
testingbeta-testingxmlhelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TwoFaced
    wrote on last edited by
    #1

    I was wondering if you can add a custom class to the My.Settings object. I mean I know you can because I did, but the problem I'm having is the class won't persist ie. the data isn't saved. The only requirment (I thought) was that the object needed to be serializable, which mine is. So am I doing something wrong, or is this just not an option. I looked for a while but just couldn't find an answer or an example. Also as a general rule, if there even is one, what kind of data should I save using the my.settings object? Should I just stick with basics like form location and color settings or is it appropriate to store whatever you want as long as you wish to store it in an xml format? Here is a very simple class I made for testing.

    <Serializable()> _
    Public Class TestClass
    Public Name As String

    Public Sub New(ByVal name As String)
        Me.Name = name
    End Sub
    

    End Class

    This is the code I used to extend My.Settings object.

    Namespace My
    Partial Friend NotInheritable Class MySettings
    Inherits Global.System.Configuration.ApplicationSettingsBase

         \_
        Public Property MyTestClass() As TestClass
            Get
                Return CType(Me("MyTestClass"), TestClass)
            End Get
            Set(ByVal value As TestClass)
                Me("MyTestClass") = value
            End Set
        End Property
    End Class
    

    End Namespace

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups