App.Config returning null values in Windows Services but returns right values in Windows Application.

Hi All,

I have created an Windows Service where I am using App.Config for global variables. But, it is always returning null values (string xyz=ConfigurationSettings.AppSettings["abc"]) for all the variables I have declared in App.Config.

(But the same thing if I am doing as a Windows Application then it's returning the right values.)

Interestingly, this same Windows Service is working properly in another machine but not working in other three machines.

Can anyone please help me to resolve this issue.

Thanks a lot.

Regards,

Lita.



Answer this question

App.Config returning null values in Windows Services but returns right values in Windows Application.

  • KurtH

    Hi Lita,

    Try Configuration Manager...

    System.Configuration.ConfigurationManager.AppSettings["key"].ToString();

    Hope this works



  • Henri20

    Hi Mubshir,

    We are using .NET Framework version 1.1 and I think Configuration Manager is part of Version 2.0. Do you have any other suggestion for me

    Thanks for your quick answers.

    Regards,

    Lita.


  • apex1

    Hi Mubshir,

    Thanks for your reply. Yes, my exe.Config file is there in the root dir of the Windows Service where .exe resides.

    Regards,

    Lita


  • DanTheStan

    Hi,

    I could have asked for App.Config but i assumed that i will be ok as you said

    _____________________________________________________________________________
    (But the same thing if I am doing as a Windows Application then it's returning the right values.)

    Interestingly, this same Windows Service is working properly in another machine but not working in other three machines.
    ______________________________________________________________________________

    Any ways thats greate, finally you caught error, Cheers!



  • Grant Perry

    Yes, you are right. Actually I had added one more variable which was not part of the Windows application. Anyway thanks for your constant response.
  • Jiming

    Hi,

    I have created many Windows Services that uses the exe.Config files to get some input. But there has never been any problem.

    Are you sure that exe.config file exists in the root dir of the Window servie where .exe reside!



  • rogueAgent

    Hi Mubshir,

    We are using .NET Framework version 1.1 and I think Configuration Manager is part of Version 2.0. Do you have any other suggestion for me

    Thanks for your quick replies.

    Regards,

    Lita.


  • Dmitry.K

    Hi Mubshir,

    I cought the error. Actually I had declared lot of variables in my App.config. In one place, instead of "value" I had written "valae" and because of this I was facing problem.

    Thanks a lot.

    Regards,

    Lita.


  • App.Config returning null values in Windows Services but returns right values in Windows Application.