【问题标题】:Configuration error c# App config配置错误 c# App config
【发布时间】:2017-02-06 05:09:17
【问题描述】:

我正在编写一个控制台应用程序,用于使用 C# 将集成文件从共享驱动器移动到 linux 服务器。新应用程序工作正常并且完成了它的工作,最近我决定使用配置文件保存属性,如文件路径。

自从我开始使用配置文件后,我收到一个错误“配置系统无法初始化”,没有进一步的细节。以下是我的配置文件中的文本

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

<Add key="UserName" value="my username" />
<Add key="HostName" value="Ip Add" />
<Add key="Password" value="MyPassword" />
<Add key="SshHostKeyFingerprint" value=" code" />
<Add key="sourcepath" value="file path" />
<Add key="destinationpath" value="file path" />
<Add key="MagentoDestinationpath" value="file path" />
<Add key="filestomove" value="*.csv" />
<Add key="Logfilepath" value="file path" />


</Appsettings>
</configuration>

我已注释掉除下一行之外的所有代码以进行故障排除

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinSCP;
using System.Threading;
using System.IO;
Using System.Configuration;
using System.Collections.Specialized;
namespace Magentogiftcard
{
 class Program
{
 static void Main(string[] args)

    {

        string Host = ConfigurationManager.AppSettings.Get("UserName");
        Console.WriteLine("Host");  

    }

    }

  }

但仍然遇到这个问题。我会给予任何帮助。

问候 贾汉吉尔·希泽

【问题讨论】:

标签: c#


【解决方案1】:

appSettings 元素及其子元素区分大小写,因此&lt;Appsettings&gt;&lt;Add… 会导致错误。

把它们改成

<appSettings>
    <add key="destinationpath" value="file path" />

Intellisense 说明了这一点:

【讨论】:

  • 顺便说一句,我认为using 指令也区分大小写(对于System.Configuration
  • 感谢您回复我。我已经换了案子,但仍然遇到同样的问题
  • 好的,appsettings 必须是 appSettings。我不确定在一个单词中间加上大写字母“S”的原因是什么。谢谢我的问题解决了
猜你喜欢
  • 2018-11-19
  • 2018-07-18
  • 1970-01-01
  • 2018-05-30
  • 1970-01-01
  • 2018-04-11
  • 1970-01-01
  • 2022-01-07
  • 2021-03-10
相关资源
最近更新 更多