views:

57

answers:

0

A while back, I wrote my own settings provider because I was having problems persisting settings in a class library. (Note - I had no problems persisting settings from an application).

Today, I just did a test of persisting class library settings and it worked, without my custom provider. The test is:

(1) Create a class library
(2) Add a setting - 'Name'
(3) Add a class with a public shared property 'Name' that reads and writes to the setting 'Name'.
(4) Create an application that references the class library, and use the shared property to read and write the 'Name' setting.

I'm sure that before the 'Name' setting would persist while the application was open but after I closed it and re-opened it, the setting would revert to the default. This is not happening now and I'd like to be sure that I was being an idiot before and not an idiot now.

Is the behaviour I'm getting now the expected behaviour?

ETA: I've noticed that the first time I create a test app, change the setting, close, and reopen, the setting is not persisted. Subsequently it is. May be I gave up after one try before. Any ideas why it's not persisted the first time?

ETA2: As an example, I have a class library called 'MyLibrary' and a test application called 'MyApp'. I do the steps 1-4 above, and below are the contents of the user.config file found at C:\Documents and Settings\User Name\Local Settings\Application Data\MyApp\MyApp.vshost.exe_Url_vi5gjcooahbdm2ma3dcay0mkexu2suul\1.0.0.0. Note: I did not touch the settings in MyApp;-

<configuration>
<configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral >
        <section name="MyLibrary.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
</configSections>
<userSettings>
    <MyLibrary.My.MySettings>
        <setting name="Name" serializeAs="String">
            <value>New changed value</value>
        </setting>
    </MyLibrary.My.MySettings>
</userSettings>