9

I have two assemblies in my application. MyApplication.BO and MyApplication.GUI.

I have configured property-settings for my BO assembly.

Now when I am trying to compile the following code:

public class MyApplicationInfo
{
 private string _nameOfTheUser;
 public string FullNameOfTheUser
 {
  get { return _nameOfTheUser; }
  set { _nameOfTheUser = value; }
 } 

 public void Save()
 {
  try
  {
   MyApplication.BO.Properties.Settings.Default.FullNameOfTheUser = this.FullNameOfTheUser;

   MyApplication.BO.Properties.Settings.Default.Save();
  }
  catch (Exception ex)
  {
   throw ex;
  }
 }
}

VS2005 is giving me the following compilation error:

Error 1 Property or indexer 'MyApplication.BO.Properties.Settings.FullNameOfTheUser' cannot be assigned to -- it is read only F:\CS\MyApplication\MyApplication.BO\MyApplicationInfo.cs 57 17 MyApplication.BO

What is wrong with my approach?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user366312
  • 16,949
  • 65
  • 235
  • 452

2 Answers2

28

In the Settings designer, make sure that the Scope property for FullNameOfTheUser is set to "User". If you create an Application-scoped setting, it is generated as a read-only property. Take a look at this article for more information.

Rory
  • 2,722
  • 1
  • 20
  • 11
2

The setting needs to have user, not application scope.

Fiona - myaccessible.website
  • 14,481
  • 16
  • 82
  • 117