2016-09-28 57 views
1

我寫的共享驅動器移動整合文件使用C#。新的應用程序工作正常,並做其工作的Linux服務器控制檯應用程序,最近我已經決定使用配置文件保存喜歡的文件路徑屬性。配置錯誤C#應用程序配置

既然我已經使用配置文件,我得到一個錯誤「配置系統初始化失敗」,沒有進一步的細節開始。下面是我的配置文件中的文本

<?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"); 

    } 

    } 

    } 

但仍然得到這個問題。我會appriciate任何幫助。

認爲 賈漢吉爾Khizer

+0

您的配置文件不正確的格式。請參考鏈接: http://stackoverflow.com/questions/6436157/configuration-system-failed-to-initialize – Ash

+0

灰您好,我是新來的C#,我有從下面的Microsoft鏈接這種格式。 https://support.microsoft.com/en-gb/kb/815786。它是用來一模一樣的格式 – Jahangir

回答

2

appSettings元素和它的子元素情況下所以<Appsettings><Add…導致該錯誤的敏感。

改變他們

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

智能感知說明了這一點:

enter image description here

+0

順便說一句,我認爲'using'指令是區分大小寫的太(爲'System.Configuration') –

+0

感謝回答還給我。我改變了案例,但仍然得到相同的問題 – Jahangir

+0

你是否也糾正了'appSettings'的情況? – stuartd