简体   繁体   中英

reading app settings as null from App.config

I am struggeling reading data from a configuration file, and all the methods online are not working for me... I have this configuration file ( App.config ):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="test" value="testVal"/>
    </appSettings>
</configuration>

And this line in my C# code

string appSettings = ConfigurationManager.AppSettings["test"];

for some reason, appSettings remains null when expected to be testVal.

This should work. Put a break point right after that and check the value. I tested same code and getting the value. If you use web application make sure you put this in web.config and not in the app.config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM