Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigurationManager Reading Wrong File

I have a solution divided into two projects, one for a Class Library and another one for Unit Tests (using NUnit 2.5). Now, on the App.config file of the Class Library project I added several lines like

<add key="KeyName" value="KeyValue"/>

which I am reading in the class library code with

ConfigurationManager.AppSettings["KeyName"].

The problem is that when I run the unit tests the class library can't access those values because even though that code is used from within the library, it goes looking for them in the App.config of the Unit Tests project. If I add those line to this file everything goes smooth, but that's of course not what I want. How can I tell ConfigurationManager to look for the keys in the right application path?

like image 907
User Avatar asked Sep 11 '26 16:09

User


1 Answers

use ConfigurationManager.OpenExeConfiguration("file path") to open correct path

like image 83
Jed I Avatar answered Sep 15 '26 01:09

Jed I



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!