How to read app.config file

Ask general questions here.
Posts: 1
Joined: Wed Mar 06, 2013 8:58 am

How to read app.config file

Post by masterpix » Wed Mar 06, 2013 9:17 am


I have a problem to read app.config file as following.

This is my app.config file.
<?xml version="1.0" encoding="utf-8" ?>
  	<startup useLegacyV2RuntimeActivationPolicy="true">
    	<supportedRuntime version="v4.0"/>
    	<supportedRuntime version="v2.0.50727"/>
    	<enforceFIPSPolicy enabled="false"/>
		<add key="mySetting" value="hello"/>
and I try to read my config in user code module with following code.
void ITestModule.Run()
      Report.Info("My Setting=" + System.Configuration.ConfigurationManager.AppSettings["mySetting"]);
But it doesn't work, the report message just show "My Setting=" with blank value.
Do I miss anything on this?

I have used Ranorex 4.0 and setting the target framework to .NET 4.0 in project properties.


User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA

Re: How to read app.config file

Post by Support Team » Thu Mar 07, 2013 11:36 am


You could try the following line to get the content (string array) of the app.config file:
string[] content  = File.ReadAllLines(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);