1

I am writing a console application for moving integration file from Shared drive to the linux server using C#.New application works fine and doing its job, recently I have decided to use configuration file save attributes like filepath.

Since I have started using the configuration file I am getting an error "Configuration system failed to initialize" with no further detail. Below is the text from my configuration file

<?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>

I have commented out all code apart from below line to trouble shoot

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

    }

    }

  }

But still getting this issue. I will appriciate any help.

regards Jahangir Khizer

Jahangir
  • 13
  • 1
  • 4
  • Your Config file is not a correct format. please refer the link : http://stackoverflow.com/questions/6436157/configuration-system-failed-to-initialize – Ash Sep 28 '16 at 09:54
  • Hi Ash, I am new to C#, I have got this format from microsoft link below. https://support.microsoft.com/en-gb/kb/815786 . It is used exactly the same format – Jahangir Sep 28 '16 at 10:03

1 Answers1

2

The appSettings element and it's child elements are case sensitive so <Appsettings> and <Add… are causing the error.

Change them to

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

Intellisense illustrates this:

enter image description here

stuartd
  • 70,509
  • 14
  • 132
  • 163