C#将设置动态添加到设置文件

C#将设置动态添加到设置文件,c#,C#,我当前正在使用以下代码将设置添加到我的设置文件中,但不断出现以下错误: 类型“providercollection”是在未定义的程序集中定义的 参考。您必须在此行添加对“程序集”的引用: Properties.Settings.Default.Providers[“LocalFileSettingsProvider”] 如何修复此错误?请提前感谢 System.Configuration.SettingsProperty property = new System.Configuration

我当前正在使用以下代码将设置添加到我的设置文件中,但不断出现以下错误:

类型“providercollection”是在未定义的程序集中定义的
参考。您必须在此行添加对“程序集”的引用: Properties.Settings.Default.Providers[“LocalFileSettingsProvider”]

如何修复此错误?请提前感谢

  System.Configuration.SettingsProperty property = new System.Configuration.SettingsProperty("CustomSetting");
  property.DefaultValue = "Default";
  property.IsReadOnly = false;
  property.PropertyType = typeof(string);
  property.Provider = Properties.Settings.Default.Providers["LocalFileSettingsProvider"];
  property.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute), new System.Configuration.UserScopedSettingAttribute());
  Properties.Settings.Default.Properties.Add(property);
您可以这样做:

  • 转到解决方案资源管理器
  • 右键单击引用
  • 添加引用
  • 搜索系统配置
  • 添加系统配置

  • 你必须添加对assembly的引用如果你不知道如何添加对assembly的引用,我可以建议你去看看一些基本的C#教程吗?这很有效我很笨:)