Jahangir Jahangir - 2 months ago 16
C# Question

Configuration error c# App config

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

Answer

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

Comments