单声道无法保存用户设置

单声道无法保存用户设置

本文介绍了单声道无法保存用户设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将用户设置保存到Mono(Ubuntu)时遇到问题.这是代码示例:

I have problems with saving user settings on Mono (Ubuntu). Here is code sample:

private void Form1_Load(object sender, EventArgs e)
{
    string savedText = Properties.Settings.Default.tbText.ToString();
    tbInput.Text = savedText;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    string textToSave = tbInput.Text;
    Properties.Settings.Default.tbText = textToSave;
    Properties.Settings.Default.tbText = Properties.Settings.Default.tbText;
    Properties.Settings.Default.Save();
}

但是我只收到空的配置,如

But i receive only empty config like

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <userSettings />
</configuration>

我已经尝试过类似的东西

I've already tried something like

Properties.Settings.Default.tbText = Properties.Settings.Default.tbText;

来自此处.但是仍然得到相同的结果.如何在Mono中使用设置?

from here. But still get same result. How can I use settings in Mono?

推荐答案

  1. 删除行

  1. Remove line

Properties.Settings.Default.tbText = Properties.Settings.Default.tbText;

  • 检查您的应用程序配置文件.可能你有这样的东西:

  • Check you application config file. Probably you have something like this:

    <configuration>
      <configSections>
        <sectionGroup name="userSettings"
                      type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <section name="ExampleApp.Properties.Settings"
                   type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
      </configSections>
      ...
      <appSettings>
        <add key="TestKey1" value="Test1" />
        <add key="TestKey2" value="Test2" />
      </appSettings>
      ...
      <userSettings>
        <ExampleApp.Properties.Settings>
          <setting name="textBox1" serializeAs="String">
            <value />
          </setting>
        </ExampleApp.Properties.Settings>
      </userSettings>
    </configuration>
    

    删除 userSettings 的sectionGroup.

    Remove sectionGroup for userSettings.

    <sectionGroup name="userSettings"
                  type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="ExampleApp.Properties.Settings"
                 type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
    

    还删除 userSettings 部分.

    <userSettings>
      ...
    </userSettings>
    

  • 删除本地 user.config .第一次运行后,它将正确地重新创建.

  • Delete your local user.config. After first run it will be recreated correctly.

    它应该工作

    这篇关于单声道无法保存用户设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-14 00:39