ConfigurationManager return null instead of string values
In my NUnit project framework, I am using ConfigurationManager.AppSettings["Company"] to read a value from the App.config file which is stored in my working directory, but the value returned is always null, even though the key exists and it has a value, Does any one know why?
App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Company" value="0000" />
</appSettings>
</configuration>
And I try to get;
var companyValue = ConfigurationManager.AppSettings["Company"];
I've also set the 'Build Action' to 'None' and 'Copy to Output Directory' to 'Copy Always'
8 Replies
have you read through the posts here? https://stackoverflow.com/questions/10766654/appsettings-get-value-from-config-file
Stack Overflow
AppSettings get value from .config file
I'm not able to access values in configuration file.
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var clientsFilePath = config.AppSettings.Settings["
specifically about renaming the config file to
YourExe.exe.config
I tried the first answer, it didn't work. Let me try the other answers.
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
if you are doing unit tests, avoid reading from files in the first place
I/O is always a source of non-determinism and should be avoided outside of integration tests etc
but beyond that, why read in config in a test? you can simply say what you want the config to be when you pass it to the system you are testing
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Hi! I'm a Software Tester. I was working on Selenium with Java. Recently we were asked to shift on C# programming language and now we have to migrate our code from Java now. So I'm learning and simultaneously migrating the code, hence a lot of things ae not clear to me yet.
I'm trying to learn from youtube but it's not being useful. Would you be kind enough to guide me through this?
I'm ready to connect on a discord call
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View