简体   繁体   中英

The name 'Properties' does not exist in the current context , with app.config

I use in a project this to save a string connection in the app.config :

 <?xml version="1.0" encoding="utf-8" ?>
 <configuration>
<configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup,  System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="ContaTroco.Properties.Settings"  type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
</configSections>
<userSettings>
    <ContaTroco.Properties.Settings>
        <setting name="servidor" serializeAs="String">
            <value />
        </setting>
        <setting name="banco" serializeAs="String">
            <value />
        </setting>
        <setting name="usuario" serializeAs="String">
            <value />
        </setting>
        <setting name="senha" serializeAs="String">
            <value />
        </setting>
    </ContaTroco.Properties.Settings>
</userSettings>

And in the code of C# i use this

        servidor = comboBox1.SelectedValue.ToString();
        usuario = txtUsuario.Text;
        password = txtPassword.Text;
        catalog = cmbBancos.Text;  
        Properties.Settings.Default.servidor = servidor;
        Properties.Settings.Default.banco = catalog;
        Properties.Settings.Default.usuario = usuario;
        Properties.Settings.Default.senha = password;
        Properties.Settings.Default.Save(); 

These codes works perfects in one project , but when i import the form to other projetco ( add existing item and i rename the namespace ) i have error on this part "The name 'Properties' does not exist in the current context", i have add the system.configuration reference to the project but the error con tinues. Thanks by any help.

If you don't have the app.config in the imported project, it might result in error. Inorder to have common config files, place these files in seperate folder, SharedConfigs and add shortcut to this file in required projects. Check this out.

多亏了所有人,我在一种情况下解决了复制文件夹属性的所有文件,在另一种情况下,我已经通过重构更改了命名空间但不起作用,我必须创建一个新表单并复制所有控件。

You are getting this error because you don't have a Properties section of your application. If you right click the project in solution explorer and choose to create a new settings file, you can can access it via Settings1."yourinfo". Settings1 and yourinfo change depending on what you named your settings file.

I fixed this by adding a new dummy setting as follows:

虚拟设置

then clicking the Save button. All errors saying "the name 'properties' does not exist in the current context" disappeared.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM