C#DLL应用程序设置为null

时间:2016-05-05 20:43:46

标签: c# dll appsettings

经过几个小时阅读互联网并试着放弃了。 此代码提供空字符串:

private void ReadAllSettings()
    {
        string pwd = Properties.Settings.Default.passwd.Length.ToString();
        Log("Password: "+ pwd);
    }

这 - 零:

private void ReadAllSettings()
    {
        System.Configuration.Configuration config = null;
        string configPath = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
        ExeConfigurationFileMap map = new ExeConfigurationFileMap();
        map.ExeConfigFilename = configPath;
        Log(configPath);
        try
        {
            config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
        }

        catch (Exception ex)
        {
            Log(ex.Message);
        }

        if (config != null)
        {
            Log("NOT NULL");
            Log(GetAppSetting(config, "passwd").Length.ToString());
        }
    }

但如果使用OpenExeConfiguration代替OpenExeConfiguration,则以:

结尾
An error occurred loading a configuration file: The parameter 'exePath' is invalid.

参数名称:exePath

位置很好。添加“.config”或将配置从ProgramFiles移动到用户的位置并明确指定位置不会改变...

即使它们是默认值,也会看到值,但如果在编译后添加\更改了值,则不会显示。

请帮助。我在这里阅读了近15个不同的答案,测试了每个代码,我见过。

0 个答案:

没有答案