Results 1 to 13 of 13

Thread: [2008] My.Settings not saving?!

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    [2008] My.Settings not saving?!

    Hey,

    I have used My.Settings for quite some time now, in both VS2005 and now in 2008, but never noticed this behaviour yet... I must be forgetting something trivial?!

    I create a StringCollection setting and manually enter some data (strings).
    I write some code to handle this, and I get it to work.

    Then, I manually add some new strings (and edit the older ones) in the Settings page, save the project, and run my code again.

    For some reason, the last changes have not been saved... Whenever I look in the settings page, I see them there, but my code cannot recognize them...

    // EDITED //

    Am I forgetting something, or is there something wrong with VS?


    EDIT
    I did add "My.Settings.Reload()" at the start of the code that displays the value... Not sure if I need to do that, but it can't hurt, can it?


    EDIT2
    It only seems to do this with a StringCollection. If I try to manually change a normal String than it picks it up fine.\


    I can reproduce this doing the following:
    - Create new project.
    - Add a StringCollection setting via the project's properties 'Settings' page, the StringCollection setting is called "Test" and it's value is one line with "line1" and a second line with "line2".
    - Make my program display the lines in a Msgbox: "MessageBox.Show(My.Settings.Test(0) & " " & My.Settings.Test(1))"
    - Output is "line1 line2"

    - Manually change the settings lines to "line1 And some text" and "line2 And some text".
    - Save project
    - Run program again, output is still "line1 line2".

    ...
    Last edited by NickThissen; Jan 16th, 2008 at 11:39 AM.

  2. #2
    Lively Member
    Join Date
    Jul 2007
    Posts
    85

    Re: [2008] My.Settings not saving?!

    Hit the Syncronize button in the upper left of the Settings page, the .config file will be recreated and your new defaults will be set.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2008] My.Settings not saving?!

    Never used that before... anyway, it says:

    Code:
    No user.config files were found in any of the following locations:
    
    [blank lines]
    I do see a 'app.config' file in the Solution explorer, which contains the right strings:

    Code:
                        <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                            <string>line1 And some text</string>
                            <string>line2 And some text</string>
                        </ArrayOfString>

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2008] My.Settings not saving?!

    look in the bin/debug & bin/release folders... delete any config files in there.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Lively Member
    Join Date
    Jul 2007
    Posts
    85

    Re: [2008] My.Settings not saving?!

    What do you have the Scope set for the string collection. With the scope set to User I can reproduce you issue, but it resolves itself when I hit syncronize or also My.Settings.Reset also will reload the defualt User settings you put in the settings desginer. With the Scope set to Application the settings are always in sync with the designer as far as I have seen.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2008] My.Settings not saving?!

    Scope is set to user. If I set it to Application I can't edit the values, right? I need to be able to edit them so I need User.

    I tried removing the config files from the debug (and release, which was empty) folder, which didn't help.
    Then I deleted the 'app.config' file via the solution explorer, and this time it worked. The changes I made came through.

    However, if I make some new changes now, the same problem arises again...

    So basically, I have to delete the app.config file everytime I might make a change to the default settings...? Seems a bit weird to me...

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2008] My.Settings not saving?!

    click the app.config file in the solution explorer, and view its properties (right click -> properties) .... there's a property called build action.... or something like that, has to do with what to do with the file when doing a build, set it to copy if newer. I'm thinking that right now it's set to not copy....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Lively Member
    Join Date
    Mar 2007
    Location
    ZA
    Posts
    65

    Re: [2008] My.Settings not saving?!

    techgnome has a point but he is overlooking the fact that the other settings are updating fine. I am unable to replicate this problem from my side.

    Have you checked what happens when you edit the settings directly in the app.config file?

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2008] My.Settings not saving?!

    Ray - did you check the age of this post first? It's nearly a year old. And what "other settings"?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Addicted Member
    Join Date
    Jul 2007
    Posts
    234

    Re: [2008] My.Settings not saving?!

    Quote Originally Posted by techgnome View Post
    click the app.config file in the solution explorer, and view its properties (right click -> properties) .... there's a property called build action.... or something like that, has to do with what to do with the file when doing a build, set it to copy if newer. I'm thinking that right now it's set to not copy....

    -tg
    i'm having the same problem, i changed Copy To Output Directory to "copy if newer" but the problem persists. here is what i have:
    Code:
    Dim existinglist As New List(Of clsReader)
    for each...
     existinglist.add(...)
    next
    My.Settings.List = existinglist
    My.Settings.Save()
    
    My.Settings.Reload()
    in Watch window I can see My.Setings.List go to 0 when I execute Reload()

    edit
    I checked other values, and they persist. For example, My.Settings.ReaderTimeout is an Integer. My.Settings.List is System.Object. could this be a problem?

    edit2
    is there a size limit? i just tried serializing to memory stream, still no go. im going to try string next

    spying on the user.config file, there is no change to the <setting name="Readers" serializeAs="Xml">
    I've gone as far as editing the Setting.Settings file and Settings.Designer to include
    Code:
    Public Property Readers() As List(Of clsReader)
                Get
                    Return CType(Me("Readers"), List(Of clsReader))
                End Get
                Set(ByVal value As List(Of clsReader))
                    Me("Readers") = value
                End Set
            End Property
    as per this this and this.

    no dice.
    Last edited by unxzst; Oct 14th, 2011 at 12:15 PM.

  11. #11
    Addicted Member
    Join Date
    Jul 2007
    Posts
    234

    Re: [2008] My.Settings not saving?!

    to hell with it, i broke my project.
    Code:
    Dim xs As New XmlSerializer(existinglist.GetType)
    Dim sr As New StringReader(My.Settings.Readers)
    Dim sw As New StringWriter
    xs.Serialize(sw, existinglist)
    My.Settings.Readers = sw.ToString
    
    Dim existingreaders As List(Of clsReader) = xs.Deserialize(sr)

  12. #12

    Re: [2008] My.Settings not saving?!

    unxzst, you should probably post in a new thread.

    EDIT: Unless you're done, in which case ignore me

  13. #13
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] My.Settings not saving?!

    Code:
            'VB2010
            'My.Settings.newVers = True in Designer
            'My.Settings.foo = StringCollection 
    
            If My.Settings.newVers Then
                My.Settings.Upgrade()
                My.Settings.newVers = False
            End If
            Debug.WriteLine(My.Settings.foo(0))
            Debug.WriteLine(My.Settings.foo(1))
            Debug.WriteLine(My.Settings.newVers)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width