[2.0 beta2] ApplicationSetting problem (C#)

L

Lloyd Dupont

I have simple setting class as follow (I want to remember a list of opened file)
----
[Serializable]
public class RecipeFileInfo
{
public string Name;
public string Location;
}
public class UserSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
public List<RecipeFileInfo> RecipeFiles
{
get { return (List<RecipeFileInfo>)this["RecipeFiles"]; }
set { this["RecipeFiles"] = value; }
}
}
----

when the program finish I call Save() on my settings like that:
----
public static class Program
{
[STAThread]
static void Main()
{
Application.Run(new MainForm());
UserSettings.Save();
}

static UserSettings usersettings;
public static UserSettings UserSettings
{
get {
if (usersettings == null)
usersettings = new UserSettings();
return usersettings;
}
}
----
during the course of the program I tested that the setting where updated.
Anyway, my setting are not saved! (and restored when the application start, of course!)
There are no new file/folder in DocumentSetting/my/ApplicationData

Is this class broken in beta2? or am I missing something?

Also VS.NET2005 (beta2) created a Settings class (in a subnamespace called property), won't this mess up with my settings?
as there should be only 1 file for both settings!
should I call Save() on both? or only 1 of them?
 
L

Lloyd Dupont

hey.. tricky...
2 issues!

1st:
the file were not in:
Document&Settings/me/ApplicationData
but in
Document&Settings/me/LocalSettings/ApplicatoinData

and 2nd:
my assemlby version info was 1.0.* so having a different version number every time.
and the application setting are store on a per version basis (I read there is some upgrade stuff, have to read that)

anyway after I setup a complete version number (0.0.1.0) I was getting this working nicely!

I have simple setting class as follow (I want to remember a list of opened file)
----
[Serializable]
public class RecipeFileInfo
{
public string Name;
public string Location;
}
public class UserSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
public List<RecipeFileInfo> RecipeFiles
{
get { return (List<RecipeFileInfo>)this["RecipeFiles"]; }
set { this["RecipeFiles"] = value; }
}
}
----

when the program finish I call Save() on my settings like that:
----
public static class Program
{
[STAThread]
static void Main()
{
Application.Run(new MainForm());
UserSettings.Save();
}

static UserSettings usersettings;
public static UserSettings UserSettings
{
get {
if (usersettings == null)
usersettings = new UserSettings();
return usersettings;
}
}
----
during the course of the program I tested that the setting where updated.
Anyway, my setting are not saved! (and restored when the application start, of course!)
There are no new file/folder in DocumentSetting/my/ApplicationData

Is this class broken in beta2? or am I missing something?

Also VS.NET2005 (beta2) created a Settings class (in a subnamespace called property), won't this mess up with my settings?
as there should be only 1 file for both settings!
should I call Save() on both? or only 1 of them?
 
G

Guest

Hi Lloyd

I am doing much the same thing as you, although when I execute:

UserSettings.Instance.CredentialsInfoList.Add(new CredentialsInfo());

Nothing gets added, no exceptions, which has left me somewhat confused as to
what is going on. I have tried decorating the property with:

[SettingsSerializeAs(SettingsSerializeAs.Binary)]

No difference, here is my code for the property:

[UserScopedSetting()]
public List<CredentialsInfo> CredentialsInfoList {
get {
return this["CredentialsInfoList"] == null
? new List<CredentialsInfo>()
: (List<CredentialsInfo>)this["CredentialsInfoList"];
}
set {
this["IMCredentialsList"] = value;
}
}

Id really appreciate you thoughts.

Craig
 
L

Lloyd Dupont

huhum...
I'm not sure if it's the source of your problem, but I can see source of bug
in your code sample.

Personally I would write
[UserScopedSetting()]
public List<CredentialsInfo> CredentialsInfoList {
get {
if(this["CredentialsInfoList"] == null) // so the return is always
assigned to the saved settings
this["CredentialsInfoList"] = new List<CredentialsInfo>();
return (List<CredentialsInfo>)this["CredentialsInfoList"];
}
set {
this["IMCredentialsList"] = value;
}
}


Craig said:
Hi Lloyd

I am doing much the same thing as you, although when I execute:

UserSettings.Instance.CredentialsInfoList.Add(new CredentialsInfo());

Nothing gets added, no exceptions, which has left me somewhat confused as
to
what is going on. I have tried decorating the property with:

[SettingsSerializeAs(SettingsSerializeAs.Binary)]

No difference, here is my code for the property:

[UserScopedSetting()]
public List<CredentialsInfo> CredentialsInfoList {
get {
return this["CredentialsInfoList"] == null
? new List<CredentialsInfo>()
: (List<CredentialsInfo>)this["CredentialsInfoList"];
}
set {
this["IMCredentialsList"] = value;
}
}

Id really appreciate you thoughts.

Craig


Lloyd Dupont said:
hey.. tricky...
2 issues!

1st:
the file were not in:
Document&Settings/me/ApplicationData
but in
Document&Settings/me/LocalSettings/ApplicatoinData

and 2nd:
my assemlby version info was 1.0.* so having a different version number
every time.
and the application setting are store on a per version basis (I read
there is some upgrade stuff, have to read that)

anyway after I setup a complete version number (0.0.1.0) I was getting
this working nicely!

I have simple setting class as follow (I want to remember a list of
opened file)
----
[Serializable]
public class RecipeFileInfo
{
public string Name;
public string Location;
}
public class UserSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
public List<RecipeFileInfo> RecipeFiles
{
get { return (List<RecipeFileInfo>)this["RecipeFiles"]; }
set { this["RecipeFiles"] = value; }
}
}
----

when the program finish I call Save() on my settings like that:
----
public static class Program
{
[STAThread]
static void Main()
{
Application.Run(new MainForm());
UserSettings.Save();
}

static UserSettings usersettings;
public static UserSettings UserSettings
{
get {
if (usersettings == null)
usersettings = new UserSettings();
return usersettings;
}
}
----
during the course of the program I tested that the setting where
updated.
Anyway, my setting are not saved! (and restored when the application
start, of course!)
There are no new file/folder in DocumentSetting/my/ApplicationData

Is this class broken in beta2? or am I missing something?

Also VS.NET2005 (beta2) created a Settings class (in a subnamespace
called property), won't this mess up with my settings?
as there should be only 1 file for both settings!
should I call Save() on both? or only 1 of them?
 
G

Guest

Hi Lloyd

Your bug fix in my get {...}, fixed the problem, many thanks!

Craig

Lloyd Dupont said:
huhum...
I'm not sure if it's the source of your problem, but I can see source of bug
in your code sample.

Personally I would write
[UserScopedSetting()]
public List<CredentialsInfo> CredentialsInfoList {
get {
if(this["CredentialsInfoList"] == null) // so the return is always
assigned to the saved settings
this["CredentialsInfoList"] = new List<CredentialsInfo>();
return (List<CredentialsInfo>)this["CredentialsInfoList"];
}
set {
this["IMCredentialsList"] = value;
}
}


Craig said:
Hi Lloyd

I am doing much the same thing as you, although when I execute:

UserSettings.Instance.CredentialsInfoList.Add(new CredentialsInfo());

Nothing gets added, no exceptions, which has left me somewhat confused as
to
what is going on. I have tried decorating the property with:

[SettingsSerializeAs(SettingsSerializeAs.Binary)]

No difference, here is my code for the property:

[UserScopedSetting()]
public List<CredentialsInfo> CredentialsInfoList {
get {
return this["CredentialsInfoList"] == null
? new List<CredentialsInfo>()
: (List<CredentialsInfo>)this["CredentialsInfoList"];
}
set {
this["IMCredentialsList"] = value;
}
}

Id really appreciate you thoughts.

Craig


Lloyd Dupont said:
hey.. tricky...
2 issues!

1st:
the file were not in:
Document&Settings/me/ApplicationData
but in
Document&Settings/me/LocalSettings/ApplicatoinData

and 2nd:
my assemlby version info was 1.0.* so having a different version number
every time.
and the application setting are store on a per version basis (I read
there is some upgrade stuff, have to read that)

anyway after I setup a complete version number (0.0.1.0) I was getting
this working nicely!

I have simple setting class as follow (I want to remember a list of
opened file)
----
[Serializable]
public class RecipeFileInfo
{
public string Name;
public string Location;
}
public class UserSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
public List<RecipeFileInfo> RecipeFiles
{
get { return (List<RecipeFileInfo>)this["RecipeFiles"]; }
set { this["RecipeFiles"] = value; }
}
}
----

when the program finish I call Save() on my settings like that:
----
public static class Program
{
[STAThread]
static void Main()
{
Application.Run(new MainForm());
UserSettings.Save();
}

static UserSettings usersettings;
public static UserSettings UserSettings
{
get {
if (usersettings == null)
usersettings = new UserSettings();
return usersettings;
}
}
----
during the course of the program I tested that the setting where
updated.
Anyway, my setting are not saved! (and restored when the application
start, of course!)
There are no new file/folder in DocumentSetting/my/ApplicationData

Is this class broken in beta2? or am I missing something?

Also VS.NET2005 (beta2) created a Settings class (in a subnamespace
called property), won't this mess up with my settings?
as there should be only 1 file for both settings!
should I call Save() on both? or only 1 of them?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top