Reputation: 100667
In running my VS2008 unit integration tests against my DAL, I have found that the assembly is reading machine.config
instead of the assembly's app.config
.
Here's the rundown on the call stack:
MyDataLayer
class inherits from a base class. Method is called GetStuff()
System.Configuration
. All good.ConfigurationManager.ConnectionStrings["MyConnStr"]
actually returns null because it's not found apparently.MyDataLayer
class, yep, MyConnStr is there.ConnectionStrings
, yes, it has one connection string. It's the one in machine.config that's over in C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config
app.config
is being superseded by the machine.config
Any help is appreciated!
Upvotes: 1
Views: 4881
Reputation: 581
This might help to some people dealing with Settings.settings
and App.config
:
Watch out for GenerateDefaultValueInCod
e attribute in the Properties pane while editing any of the value (rows) in the Settings.settings grid in Visual Studio (VS2008 in my case).
If you set GenerateDefaultValueInCode
to True (True is the default here!), the default value is compiled into the exe (or dll), you can find it embedded in the file when you open it in a plain text editor.
I was working on a console application and if I had defaults in the exe, the application always ignored the config file placed in the same directory!
Quite a nightmare and no information about this on the whole internet.
Upvotes: 2
Reputation: 46605
Not sure if this applies to you, but you need to make sure the configuration string is in your Unit Test Project's app.config, not your DataLayer project.
Upvotes: 5