SettingsPropertyNotFoundException in VS2010 unit tests
-
Tuesday, May 18, 2010 10:32 PM
I have a class library project (Project ACME) that I am trying to unit test in vs2010. Project Acme references Project ACME DAL. Project ACME Dal has Project properties for 4 different sql connection strings. When the code tries to lookup the actual sql connect string via property configuration, it blows up. Here is the code:
public IDbConnection GetConfigConnection()
{
//Exception thrown here during unit test:
//System.Configuration.SettingsPropertyNotFoundException: The settings property 'ConfigDBConnectString' was not found.
return new SqlConnection(Properties.Settings.Default.ConfigDBConnectString);
}
I copied the app.config from Project ACME Dal to the unit test app.config. It still blows up for some reason. If it makes any difference these projects used to be in vs2008 where they tested fine. Not sure if migrating to vs2010 would cause this. Anyone else run into this or similar?
thanks!
All Replies
-
Wednesday, May 19, 2010 7:04 PM
Quick update. One thing I noticed is that the App.Config in the unit test was not set to copy to the output folder. I changed it to always copy. Now that I made the change I get a different error when attempting to resolve the connect string property setting:
Settings.Designer.cs:
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
[global::System.Configuration.DefaultSettingValueAttribute("server=MyServer;database=MyDb;Application Name=MyApp;integrated security=SSPI;" +
"persist security info=False;Trusted_Connection=Yes;")]
public string ConfigDBConnectString {
get {
return ((string)(this["ConfigDBConnectString"])); //System.NullReferenceException: Object reference not set to an instance of an object.
}
}

